简体   繁体   English

AWS Amplify 上的 Gatsby 部署失败

[英]Gatsby deployment failure on AWS Amplify

I have a gatsby portfolio page that's simply all in an index.js file.我有一个 gatsby 投资组合页面,它只是在 index.js 文件中。

I am having trouble deploying it on AWS Amplify, here are the build logs:我在 AWS Amplify 上部署它时遇到问题,以下是构建日志:

                                 # Starting phase: preBuild
                                 # Executing command: npm install
2021-11-02T07:59:54.079Z [INFO]: > msgpackr-extract@1.0.15 install /codebuild/output/src648320162/src/simonshampoo.io/node_modules/msgpackr-extract
                                 > node-gyp-build
2021-11-02T07:59:54.283Z [INFO]: > lmdb-store@1.6.11 install /codebuild/output/src648320162/src/simonshampoo.io/node_modules/lmdb-store
                                 > node-gyp-build
2021-11-02T07:59:54.534Z [INFO]: > core-js@3.18.3 postinstall /codebuild/output/src648320162/src/simonshampoo.io/node_modules/core-js
                                 > node -e "try{require('./postinstall')}catch(e){}"
2021-11-02T07:59:54.582Z [INFO]: [96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling JavaScript standard library![0m
                                 [96mThe project needs your help! Please consider supporting of core-js:[0m
                                 [96m>[94m https://opencollective.com/core-js [0m
                                 [96m>[94m https://patreon.com/zloirock [0m
                                 [96m>[94m https://paypal.me/zloirock [0m
                                 [96m>[94m bitcoin: bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz [0m
                                 [96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good job -)[0m
2021-11-02T07:59:54.588Z [INFO]: > core-js-pure@3.18.3 postinstall /codebuild/output/src648320162/src/simonshampoo.io/node_modules/core-js-pure
                                 > node -e "try{require('./postinstall')}catch(e){}"
2021-11-02T07:59:54.942Z [INFO]: > gatsby-telemetry@3.0.0 postinstall /codebuild/output/src648320162/src/simonshampoo.io/node_modules/gatsby-telemetry
                                 > node src/postinstall.js || true
2021-11-02T07:59:55.003Z [INFO]: > gatsby-cli@4.0.0 postinstall /codebuild/output/src648320162/src/simonshampoo.io/node_modules/gatsby-cli
                                 > node scripts/postinstall.js
2021-11-02T07:59:55.057Z [INFO]: > gatsby@4.0.1 postinstall /codebuild/output/src648320162/src/simonshampoo.io/node_modules/gatsby
                                 > node scripts/postinstall.js
2021-11-02T07:59:56.402Z [WARNING]: npm
2021-11-02T07:59:56.403Z [WARNING]: WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
                                    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2021-11-02T07:59:56.407Z [INFO]: added 1667 packages from 742 contributors and audited 1668 packages in 46.524s
2021-11-02T07:59:57.367Z [INFO]: 290 packages are looking for funding
                                 run `npm fund` for details
2021-11-02T07:59:57.369Z [INFO]: found 17 vulnerabilities (7 moderate, 9 high, 1 critical)
                                 run `npm audit fix` to fix them, or `npm audit` for details
2021-11-02T07:59:57.437Z [INFO]: # Completed phase: preBuild
                                 # Starting phase: build
                                 # Executing command: npm run build
2021-11-02T07:59:57.634Z [INFO]: > new-portfolio@1.0.0 build /codebuild/output/src648320162/src/simonshampoo.io
                                 > gatsby build
2021-11-02T07:59:58.185Z [WARNING]: error Gatsby requires Node.js 14.15.0 or higher (you have v12.21.0).
                                    Upgrade Node to the latest stable release: https://gatsby.dev/upgrading-node-js
2021-11-02T07:59:58.502Z [WARNING]: npm
2021-11-02T07:59:58.502Z [WARNING]: ERR! code ELIFECYCLE
                                    npm ERR! errno 1
2021-11-02T07:59:58.504Z [WARNING]: npm
2021-11-02T07:59:58.505Z [WARNING]: ERR! new-portfolio@1.0.0 build: `gatsby build`
                                    npm ERR! Exit status 1
                                    npm ERR!
                                    npm ERR! Failed at the new-portfolio@1.0.0 build script.
                                    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-11-02T07:59:58.509Z [WARNING]: 
2021-11-02T07:59:58.510Z [WARNING]: npm ERR! A complete log of this run can be found in:
                                    npm ERR!     /root/.npm/_logs/2021-11-02T07_59_58_505Z-debug.log
2021-11-02T07:59:58.510Z [HELP]: Outputting the npm debug log
                                 0 info it worked if it ends with ok
                                 1 verbose cli [
                                 1 verbose cli   '/root/.nvm/versions/node/v12.21.0/bin/node',
                                 1 verbose cli   '/root/.nvm/versions/node/v12.21.0/bin/npm',
                                 1 verbose cli   'run',
                                 1 verbose cli   'build'
                                 1 verbose cli ]
                                 2 info using npm@6.14.11
                                 3 info using node@v12.21.0
                                 4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
                                 5 info lifecycle new-portfolio@1.0.0~prebuild: new-portfolio@1.0.0
                                 6 info lifecycle new-portfolio@1.0.0~build: new-portfolio@1.0.0
                                 7 verbose lifecycle new-portfolio@1.0.0~build: unsafe-perm in lifecycle true
                                 8 verbose lifecycle new-portfolio@1.0.0~build: PATH: /root/.nvm/versions/node/v12.21.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/codebuild/output/src648320162/src/simonshampoo.io/node_modules/.bin:/usr/local/rvm/gems/ruby-2.4.6/bin:/usr/local/rvm/gems/ruby-2.4.6@global/bin:/usr/local/rvm/rubies/ruby-2.4.6/bin:/usr/local/rvm/bin:/root/.yarn/bin:/root/.config/yarn/global/node_modules/.bin:/root/.nvm/versions/node/v12.21.0/bin:/root/.local/bin:/root/.local/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools
                                 9 verbose lifecycle new-portfolio@1.0.0~build: CWD: /codebuild/output/src648320162/src/simonshampoo.io
                                 10 silly lifecycle new-portfolio@1.0.0~build: Args: [ '-c', 'gatsby build' ]
                                 11 silly lifecycle new-portfolio@1.0.0~build: Returned: code: 1  signal: null
                                 12 info lifecycle new-portfolio@1.0.0~build: Failed to exec build script
                                 13 verbose stack Error: new-portfolio@1.0.0 build: `gatsby build`
                                 13 verbose stack Exit status 1
                                 13 verbose stack     at EventEmitter.<anonymous> (/root/.nvm/versions/node/v12.21.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
                                 13 verbose stack     at EventEmitter.emit (events.js:314:20)
                                 13 verbose stack     at ChildProcess.<anonymous> (/root/.nvm/versions/node/v12.21.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
                                 13 verbose stack     at ChildProcess.emit (events.js:314:20)
                                 13 verbose stack     at maybeClose (internal/child_process.js:1022:16)
                                 13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
                                 14 verbose pkgid new-portfolio@1.0.0
                                 15 verbose cwd /codebuild/output/src648320162/src/simonshampoo.io
                                 16 verbose Linux 4.14.248-189.473.amzn2.x86_64
                                 17 verbose argv "/root/.nvm/versions/node/v12.21.0/bin/node" "/root/.nvm/versions/node/v12.21.0/bin/npm" "run" "build"
                                 18 verbose node v12.21.0
                                 19 verbose npm  v6.14.11
                                 20 error code ELIFECYCLE
                                 21 error errno 1
                                 22 error new-portfolio@1.0.0 build: `gatsby build`
                                 22 error Exit status 1
                                 23 error Failed at the new-portfolio@1.0.0 build script.
                                 23 error This is probably not a problem with npm. There is likely additional logging output above.
                                 24 verbose exit [ 1, true ]
2021-11-02T07:59:58.513Z [ERROR]: !!! Build failed
2021-11-02T07:59:58.513Z [ERROR]: !!! Non-Zero Exit Code detected
2021-11-02T07:59:58.513Z [INFO]: # Starting environment caching...
2021-11-02T07:59:58.513Z [INFO]: # Environment caching completed
Terminating logging...

It says that my node is outdated, but I do node -v in the project directory and it says I have v14.8.1 , so I am confused.它说我的节点已过时,但我在项目目录中执行node -v并说我有v14.8.1 ,所以我很困惑。 Is there another problem?还有其他问题吗? public subdirectory was previously gitignored, so I removed it from there, but that doesn't seem to do anything. public子目录以前是 gitignored,所以我从那里删除了它,但这似乎没有任何作用。 I can't find much information about deployment failures on Amplify since it's supposed to be straightforward.我在 Amplify 上找不到很多关于部署失败的信息,因为它应该很简单。 Do I have to use nvm ?我必须使用nvm吗? It also won't even deploy on Github pages-- it just shows the "Gatsby Minimal Starter" page in my repo.它甚至不会部署在 Github 页面上——它只是在我的 repo 中显示“Gatsby Minimal Starter”页面。

I think there's a mismatching Node version between your local environment and the AWS Amplify's.我认为您的本地环境和 AWS Amplify 的 Node 版本不匹配。 If you run different versions of Node, the installed dependencies in the npm install will be different so your application will behave differently in both environments, assuming that it builds locally (if don't, there might be another underlying problem).如果您运行不同版本的 Node,则npm install安装的依赖项将不同,因此您的应用程序在两种环境中的行为都会不同,假设它是在本地构建的(如果不是,则可能存在另一个潜在问题)。

As you pointed, you can use nvm to set the provision version.正如您所指出的,您可以使用nvm来设置配置版本。 Based on How to change Node Version in Provision Step in Amplify Console you can try:基于如何在 Amplify 控制台中的配置步骤中更改节点版本,您可以尝试:

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

Using a .nvmrc file in the root of the project should also work.在项目的根目录中使用.nvmrc文件也应该有效。 You can set it directly by:您可以通过以下方式直接设置:

node -v > .nvmrc

Out of the scope of the question: /public directory should be always ignored because it's autogenerated in each build, so it will be overridden.超出问题的范围: /public目录应该始终被忽略,因为它是在每个构建中自动生成的,因此它将被覆盖。 There's no point in pushing it and it will save you MB bandwidth.推动它毫无意义,它将为您节省 MB 带宽。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM