How to change Node Version in Provision Step in Amplify Console

白昼怎懂夜的黑 提交于 2020-12-04 15:53:29

问题


I'm facing the problem that I cant build my Angular app through the AWS Amplify Console: "You are running version v8.12.0 of Node.js, which is not supported by Angular CLI 8.0+. The official Node.js version that is supported is 10.9 or greater. Please visit https://nodejs.org/en/ to find instructions on how to update Node.js."

Now I want to set the default node version of the docker container in the provision step to VERSION_NODE_10 which is already defined in the container.

# Framework Versions
ENV VERSION_NODE_8=8.12.0
ENV VERSION_NODE_6=6
ENV VERSION_NODE_10=10
ENV VERSION_NODE_DEFAULT=$VERSION_NODE_8 <-- Change this to $VERSION_NODE_10
ENV VERSION_RUBY_2_3=2.3.6
ENV VERSION_RUBY_2_4=2.4.3
ENV VERSION_RUBY_DEFAULT=$VERSION_RUBY_2_3
ENV VERSION_HUGO=0.51
ENV VERSION_YARN=1.13.0

amplify.yml:

version: 0.1
backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - npm ci
    build:
      commands:
        - node -v
        - npm run-script build
  artifacts:
    baseDirectory: dist/cr-client
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

Does anyone know how to change the default?


回答1:


AWS Amplify use nvm to handle node version. Try this:

version: 0.1
backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - nvm use $VERSION_NODE_10
        - npm ci
    build:
      commands:
        - nvm use $VERSION_NODE_10
        - node -v
        - npm run-script build
  artifacts:
    baseDirectory: dist/cr-client
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*



回答2:


The correct answer actually isn't the right one.

You should use a custom build image of NodeJS to run your application properly without changing the node version by nvm.

To do that:

  1. Open the "Amplify Console"
  2. Open "All Apps"
  3. Choose the app you're going to change the NodeJS version
  4. Open "Build Settings"
  5. Scroll down to "Build image settings" box and hit "edit" button
  6. At "Build Image" dropdown, choose the option "Build image"
  7. A new input field will appear just below this dropdown, now write the Docker Image Name (same used in Dockefile) you are looking for. For example node:12.16.1
  8. Save
  9. Redeploy any build.



回答3:


The accepted answer did not work for me.

The only way to change the node version in the provision step is to have your own build setting.

However, there is an easier way to accomplish this.

In my case, I wanted the latest node 10 version. And adding nvm install in the prebuild step worked.

frontend:
  phases:
    preBuild:
      commands:
        - nvm install 10

You can install and use any node version in the amplify by installing it in prebuild steps. Use nvm to switch the node version.

preBuild:
  commands:
    - nvm install <node version>

Amplify Console output:

# Executing command: nvm install 10

2020-09-09T13:36:19.465Z [INFO]: Downloading and installing node v10.22.0...
2020-09-09T13:36:19.544Z [WARNING]: Downloading https://nodejs.org/dist/v10.22.0/node-v10.22.0-linux-x64.tar.gz...
2020-09-09T13:36:19.664Z [WARNING]: ########
2020-09-09T13:36:19.665Z [WARNING]: 11.9%
2020-09-09T13:36:19.765Z [WARNING]: #######
2020-09-09T13:36:19.765Z [WARNING]: ########################                                           43.5%
2020-09-09T13:36:19.832Z [WARNING]: ################################
2020-09-09T13:36:19.832Z [WARNING]: ######################################## 100.0%
2020-09-09T13:36:19.844Z [WARNING]: Computing checksum with sha256sum
2020-09-09T13:36:19.934Z [WARNING]: Checksums matched!

2020-09-09T13:36:20.842Z [INFO]: Now using node v10.22.0 (npm v6.14.6)


来源:https://stackoverflow.com/questions/56444337/how-to-change-node-version-in-provision-step-in-amplify-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!