【问题标题】:aws/azure fail to run a build for react appaws/azure 无法为 React 应用程序运行构建
【发布时间】:2021-10-10 18:07:13
【问题描述】:

已解决:

问题是我已经将我的 10400 个 json 数据对象保存为 .js 数组,这使得构建需要很长时间(我只是不知道如何处理 json),现在它是 .json 并且一切正常。


我制作了一个 react 应用程序,它在 localhost(以及 ngrok)上运行良好,但是当我尝试将应用程序部署到 Azure(或 AWS)时,构建失败。

在我的电脑上我尝试了npm run build,它成功了,但花了大约 10 分钟(m1 macbbok pro)。

也许有办法在我的计算机上运行构建并将该构建推送到 AWS? (因此 AWS 不必在构建上浪费时间然后失败)

package.json

    {
  "name": "az-demo",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "qrcode": "^1.4.4",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-qrcodes": "^1.0.7",
    "react-scripts": "4.0.3",
    "react-table": "^7.7.0",
    "web-vitals": "^1.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

aws 日志:

                                     # Starting phase: preBuild
                                 # Executing command: npm ci
2021-10-08T21:24:48.088Z [INFO]: > core-js-pure@3.18.2 postinstall /codebuild/output/src164638141/src/TAU-ICS/node_modules/core-js-pure
                                 > node -e "try{require('./postinstall')}catch(e){}"
2021-10-08T21:24:48.130Z [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-10-08T21:24:48.242Z [INFO]: > core-js@2.6.12 postinstall /codebuild/output/src164638141/src/TAU-ICS/node_modules/babel-runtime/node_modules/core-js
                                 > node -e "try{require('./postinstall')}catch(e){}"
2021-10-08T21:24:48.282Z [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 on Open Collective or Patreon: [0m
                                 [96m>[94m https://opencollective.com/core-js [0m
                                 [96m>[94m https://www.patreon.com/zloirock [0m
                                 [96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good job -)[0m
2021-10-08T21:24:48.316Z [INFO]: > ejs@2.7.4 postinstall /codebuild/output/src164638141/src/TAU-ICS/node_modules/ejs
                                 > node ./postinstall.js
2021-10-08T21:24:48.352Z [INFO]: Thank you for installing [35mEJS[0m: built with the [32mJake[0m JavaScript build tool ([32mhttps://jakejs.com/[0m)
2021-10-08T21:24:48.516Z [INFO]: > fsevents@1.2.13 install /codebuild/output/src164638141/src/TAU-ICS/node_modules/webpack-dev-server/node_modules/fsevents
                                 > node install.js
2021-10-08T21:24:48.554Z [INFO]: 
2021-10-08T21:24:48.555Z [INFO]: Skipping 'fsevents' build as platform linux is not supported
2021-10-08T21:24:48.581Z [INFO]: > fsevents@1.2.13 install /codebuild/output/src164638141/src/TAU-ICS/node_modules/watchpack-chokidar2/node_modules/fsevents
                                 > node install.js
2021-10-08T21:24:48.617Z [INFO]: 
2021-10-08T21:24:48.617Z [INFO]: Skipping 'fsevents' build as platform linux is not supported
2021-10-08T21:24:48.768Z [INFO]: > core-js@3.18.2 postinstall /codebuild/output/src164638141/src/TAU-ICS/node_modules/core-js
                                 > node -e "try{require('./postinstall')}catch(e){}"
2021-10-08T21:24:49.236Z [INFO]: added 1990 packages in 10.711s
2021-10-08T21:24:49.248Z [INFO]: # Completed phase: preBuild
                                 # Starting phase: build
2021-10-08T21:24:49.249Z [INFO]: # Executing command: npm run build
2021-10-08T21:24:49.409Z [INFO]: > az-demo@0.1.0 build /codebuild/output/src164638141/src/TAU-ICS
                                 > react-scripts build
2021-10-08T21:24:50.514Z [INFO]: Creating an optimized production build...
2021-10-08T21:25:40.146Z [INFO]: <--- Last few GCs --->
                                 [1265:0x4bdfeb0]    49291 ms: Scavenge 1974.9 (1996.2) -> 1974.0 (2019.0) MB, 11.0 / 0.0 ms  (average mu = 0.372, current mu = 0.462) allocation failure
                                 [1265:0x4bdfeb0]    49328 ms: Scavenge 1990.4 (2019.0) -> 1989.6 (2020.2) MB, 14.0 / 0.0 ms  (average mu = 0.372, current mu = 0.462) allocation failure
                                 [1265:0x4bdfeb0]    49347 ms: Scavenge 1991.3 (2020.2) -> 1989.5 (2033.0) MB, 16.7 / 0.0 ms  (average mu = 0.372, current mu = 0.462) allocation failure
                                 <--- JS stacktrace --->
                                 ==== JS stack trace =========================================
                                 0: ExitFrame [pc: 0x140a7f9]
                                 Security context: 0x11c972a408d1 <JSObject>
                                 1: /* anonymous */(aka /* anonymous */) [0x20231a5c2891] [/codebuild/output/src164638141/src/TAU-ICS/node_modules/webpack-sources/lib/ReplaceSource.js:~122] [pc=0x20e8ba2fedd9](this=0x38c384a804b1 <undefined>,0x3e520dbd80f9 <String[7]: "type":>,0x3936c6875699 <Object map = 0x23df49a78f9>)
                                 2: walk(aka SourceNode_walk) [0x12a2576ee5f1] [/codebuild/output/sr...
2021-10-08T21:25:40.147Z [WARNING]: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
2021-10-08T21:25:40.219Z [WARNING]: 1: 0xa18150 node::Abort() [/root/.nvm/versions/node/v12.21.0/bin/node]
2021-10-08T21:25:40.219Z [WARNING]: 2: 0xa1855c node::OnFatalError(char const*, char const*) [/root/.nvm/versions/node/v12.21.0/bin/node]
2021-10-08T21:25:40.220Z [WARNING]: 3: 0xb9705e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/root/.nvm/versions/node/v12.21.0/bin/node]
2021-10-08T21:25:40.221Z [WARNING]: 4: 0xb973d9 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/root/.nvm/versions/node/v12.21.0/bin/node]
2021-10-08T21:25:40.221Z [WARNING]: 5: 0xd54655  [/root/.nvm/versions/node/v12.21.0/bin/node]
2021-10-08T21:25:40.222Z [WARNING]: 6: 0xd54ce6 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/root/.nvm/versions/node/v12.21.0/bin/node]
2021-10-08T21:25:40.222Z [WARNING]: 7: 0xd615a5 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/root/.nvm/versions/node/v12.21.0/bin/node]
2021-10-08T21:25:40.223Z [WARNING]: 8: 0xd62455 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/root/.nvm/versions/node/v12.21.0/bin/node]
2021-10-08T21:25:40.223Z [WARNING]: 9: 0xd63aff v8::internal::Heap::HandleGCRequest() [/root/.nvm/versions/node/v12.21.0/bin/node]
2021-10-08T21:25:40.224Z [WARNING]: 10: 0xd12565 v8::internal::StackGuard::HandleInterrupts() [/root/.nvm/versions/node/v12.21.0/bin/node]
2021-10-08T21:25:40.224Z [WARNING]: 11: 0x106dba6 v8::internal::Runtime_StackGuard(int, unsigned long*, v8::internal::Isolate*) [/root/.nvm/versions/node/v12.21.0/bin/node]
2021-10-08T21:25:40.225Z [WARNING]: 12: 0x140a7f9  [/root/.nvm/versions/node/v12.21.0/bin/node]
2021-10-08T21:25:57.789Z [WARNING]: npm
2021-10-08T21:25:57.790Z [WARNING]: ERR! code ELIFECYCLE
                                    npm ERR! errno 1
2021-10-08T21:25:57.791Z [WARNING]: npm
2021-10-08T21:25:57.791Z [WARNING]: ERR! az-demo@0.1.0 build: `react-scripts build`
                                    npm ERR! Exit status 1
                                    npm ERR!
                                    npm ERR! Failed at the az-demo@0.1.0 build script.
                                    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-10-08T21:25:57.814Z [WARNING]: 
2021-10-08T21:25:57.815Z [WARNING]: npm ERR! A complete log of this run can be found in:
                                    npm ERR!     /root/.npm/_logs/2021-10-08T21_25_57_791Z-debug.log
2021-10-08T21:25:57.815Z [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 az-demo@0.1.0~prebuild: az-demo@0.1.0
                                 6 info lifecycle az-demo@0.1.0~build: az-demo@0.1.0
                                 7 verbose lifecycle az-demo@0.1.0~build: unsafe-perm in lifecycle true
                                 8 verbose lifecycle az-demo@0.1.0~build: PATH: /root/.nvm/versions/node/v12.21.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/codebuild/output/src164638141/src/TAU-ICS/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 az-demo@0.1.0~build: CWD: /codebuild/output/src164638141/src/TAU-ICS
                                 10 silly lifecycle az-demo@0.1.0~build: Args: [ '-c', 'react-scripts build' ]
                                 11 silly lifecycle az-demo@0.1.0~build: Returned: code: 1  signal: null
                                 12 info lifecycle az-demo@0.1.0~build: Failed to exec build script
                                 13 verbose stack Error: az-demo@0.1.0 build: `react-scripts 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 az-demo@0.1.0
                                 15 verbose cwd /codebuild/output/src164638141/src/TAU-ICS
                                 16 verbose Linux 4.14.243-185.433.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 az-demo@0.1.0 build: `react-scripts build`
                                 22 error Exit status 1
                                 23 error Failed at the az-demo@0.1.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-10-08T21:25:57.818Z [ERROR]: !!! Build failed
2021-10-08T21:25:57.818Z [ERROR]: !!! Non-Zero Exit Code detected
2021-10-08T21:25:57.818Z [INFO]: # Starting environment caching...
2021-10-08T21:25:57.819Z [INFO]: # Environment caching completed
Terminating logging...

【问题讨论】:

    标签: node.js reactjs amazon-web-services azure npm


    【解决方案1】:

    Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

    将您的 codebuild 计算规格更改为可能与您的 m1 相同。之后你就可以优化,看看使用了多少内存和cpu。

    https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html

    对于 azure 你也可以这样做

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-04
      • 2018-02-03
      • 2018-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多