如何解决无法编译NPM运行构建的应用程序做出反应错误”。无法再缩小捆绑。”?

问题描述 投票:3回答:1

我跑了“创建 - 反应 - 应用前端”(加载结果到repository是否有帮助)cd到前端,然后成功地跑“故宫运行测试”,但是当我跑了“新公共管理运行构建”我收到以下错误:

Creating an optimized production build...
Failed to compile.

Failed to minify the bundle. Error: static/js/main.6eb16068.chunk.js from Terser
TypeError: Cannot read property 'minify' of undefined
    at compiler.run (/Users/jo/sdk/my-app/node_modules/react-scripts/scripts/build.js:169:23)
    at finalCallback (/Users/jo/sdk/my-app/node_modules/webpack/lib/Compiler.js:210:39)
    at hooks.done.callAsync.err (/Users/jo/sdk/my-app/node_modules/webpack/lib/Compiler.js:226:13)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jo/sdk/my-app/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/jo/sdk/my-app/node_modules/tapable/lib/Hook.js:154:20)
    at onCompiled (/Users/jo/sdk/my-app/node_modules/webpack/lib/Compiler.js:224:21)
    at hooks.afterCompile.callAsync.err (/Users/jo/sdk/my-app/node_modules/webpack/lib/Compiler.js:553:14)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jo/sdk/my-app/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/jo/sdk/my-app/node_modules/tapable/lib/Hook.js:154:20)
    at compilation.seal.err (/Users/jo/sdk/my-app/node_modules/webpack/lib/Compiler.js:550:30)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jo/sdk/my-app/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/jo/sdk/my-app/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.optimizeAssets.callAsync.err (/Users/jo/sdk/my-app/node_modules/webpack/lib/Compilation.js:1295:35)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/jo/sdk/my-app/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/jo/sdk/my-app/node_modules/tapable/lib/Hook.js:154:20)
    at hooks.optimizeChunkAssets.callAsync.err (/Users/jo/sdk/my-app/node_modules/webpack/lib/Compilation.js:1286:32)
Read more here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `react-scripts 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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jo/.npm/_logs/2019-02-02T22_35_37_563Z-debug.log

这是日志:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
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: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/jo/sdk/my-app/node_modules/.bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/spark/bin:/usr/local/scala/bin:/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/opt/X11/bin:/Applications/DevDesktop/tools:/usr/local/bin
9 verbose lifecycle [email protected]~build: CWD: /Users/jo/sdk/my-app
10 silly lifecycle [email protected]~build: Args: [ '-c', 'react-scripts 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: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:189:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:189:13)
13 verbose stack     at maybeClose (internal/child_process.js:970:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid [email protected]
15 verbose cwd /Users/jo/sdk/my-app
16 verbose Darwin 17.7.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v10.15.1
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] build: `react-scripts 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 ]

当我搜索,我发现这个bug fix

不过,我不知道这意味着什么?我将如何实现所提到的解决?我看了一下minify issue,但我的package.json文件显示反应的脚本@> = 2.0.0:

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "react-scripts": "2.1.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}
reactjs
1个回答
2
投票

尝试添加这在你的package.json你的依赖:"terser": "3.14.1",

这个问题来自于更简洁(3.16)的当前版本,所以现在它需要保持固定的版本。

© www.soinside.com 2019 - 2024. All rights reserved.