我有一個 gatsby 投資組合頁面,它只是在 index.js 檔案中。
我在 AWS Amplify 上部署它時遇到問題,以下是構建日志:
# Starting phase: preBuild
# Executing command: npm install
2021-11-02T07:59:54.079Z [INFO]: > [email protected] install /codebuild/output/src648320162/src/simonshampoo.io/node_modules/msgpackr-extract
> node-gyp-build
2021-11-02T07:59:54.283Z [INFO]: > [email protected] install /codebuild/output/src648320162/src/simonshampoo.io/node_modules/lmdb-store
> node-gyp-build
2021-11-02T07:59:54.534Z [INFO]: > [email protected] 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]: > [email protected] 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]: > [email protected] postinstall /codebuild/output/src648320162/src/simonshampoo.io/node_modules/gatsby-telemetry
> node src/postinstall.js || true
2021-11-02T07:59:55.003Z [INFO]: > [email protected] postinstall /codebuild/output/src648320162/src/simonshampoo.io/node_modules/gatsby-cli
> node scripts/postinstall.js
2021-11-02T07:59:55.057Z [INFO]: > [email protected] 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: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: 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]: > [email protected] 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! [email protected] build: `gatsby build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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 [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]~prebuild: [email protected]
6 info lifecycle [email protected]~build: [email protected]
7 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~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 [email protected]~build: CWD: /codebuild/output/src648320162/src/simonshampoo.io
10 silly lifecycle [email protected]~build: Args: [ '-c', 'gatsby build' ]
11 silly lifecycle [email protected]~build: Returned: code: 1 signal: null
12 info lifecycle [email protected]~build: Failed to exec build script
13 verbose stack Error: [email protected] 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 [email protected]
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 [email protected] build: `gatsby build`
22 error Exit status 1
23 error Failed at the [email protected] 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...
它說我的節點已經過時了,但我node -v在專案目錄中這樣做了,它說我有v14.8.1,所以我很困惑。還有其他問題嗎?public子目錄以前被 gitignored,所以我從那里洗掉了它,但這似乎沒有做任何事情。我在 Amplify 上找不到很多關于部署失敗的資訊,因為它應該很簡單。我必須使用nvm嗎?它甚至不會部署在 Github 頁面上——它只是在我的 repo 中顯示“Gatsby Minimal Starter”頁面。
uj5u.com熱心網友回復:
我認為您的本地環境和 AWS Amplify 的 Node 版本不匹配。如果您運行不同版本的 Node,則安裝的依賴項npm install將不同,因此您的應用程式在兩種環境中的行為將不同,假設它是在本地構建的(如果不是,則可能存在另一個潛在問題)。
正如您所指出的,您可以使用nvm來設定配置版本。基于如何在 Amplify 控制臺中的配置步驟中更改節點版本,您可以嘗試:
frontend:
phases:
preBuild:
commands:
- nvm install your_local_node_version
使用.nvmrc專案根目錄中的檔案也應該有效。您可以通過以下方式直接設定:
node -v > .nvmrc
超出問題的范圍:/public應該始終忽略目錄,因為它是在每個構建中自動生成的,因此它將被覆寫。推動它毫無意義,它將為您節省 MB 帶寬。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/346018.html
