无法缩小npm run build上的代码

时间:2018-07-23 00:58:51

标签: javascript json reactjs npm create-react-app

我已经完成了使用创建的react应用程序  create-react-app ,我在npm start上在本地运行时没有任何问题,但是当我尝试使用 npm-build

我在缩小代码时遇到错误。我尝试克隆项目并尝试构建它,尝试创建测试项目并尝试npm build,但没有任何问题,只有当我尝试构建我的完整项目时。

这是我的错误

> test@0.1.0 build C:\Users\Jonathan Stroz\Documents\HackerNews-Production-master
> react-scripts build

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

Failed to minify the code from this file:

        ./node_modules/newsapi/index.js:20

Read more here: 

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

这是我的错误文件

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\Jonathan Stroz\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using npm@6.2.0
3 info using node@v9.2.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle test@0.1.0~prebuild: test@0.1.0
6 info lifecycle test@0.1.0~build: test@0.1.0
7 verbose lifecycle test@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle test@0.1.0~build: PATH: C:\Users\Jonathan Stroz\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Jonathan Stroz\Documents\HackerNews-Production-master\node_modules\.bin;C:\Users\Jonathan Stroz\gcc\bin;C:\Users\Jonathan Stroz\gcc\libexec\gcc\i686-pc-mingw32\4.9.2;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Python33;C:\Python33\Scripts;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\dotnet\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Yarn\bin\;C:\Users\Jonathan Stroz\gcc\bin;C:\Users\Jonathan Stroz\gcc\libexec\gcc\i686-pc-mingw32\4.9.2;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\MATLAB\R2016b\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;PATH%;C:\Python34\Scripts;C:\Program Files\Java\jdk1.8.0_144\bin;C:\Users\Jonathan Stroz\AppData\Local\GitHubDesktop\bin;C:\Users\Jonathan Stroz\AppData\Local\atom\bin;C:\Users\ugur\AppData\Roaming\npm;C:\Users\Jonathan Stroz\AppData\Roaming\npm;;C:\Users\Jonathan Stroz\AppData\Local\Microsoft\WindowsApps;C:\Users\Jonathan Stroz\AppData\Local\Yarn\bin
9 verbose lifecycle test@0.1.0~build: CWD: C:\Users\Jonathan Stroz\Documents\HackerNews-Production-master
10 silly lifecycle test@0.1.0~build: Args: [ '/d /s /c', 'react-scripts build' ]
11 silly lifecycle test@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle test@0.1.0~build: Failed to exec build script
13 verbose stack Error: test@0.1.0 build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\Jonathan Stroz\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:304:16)
13 verbose stack     at EventEmitter.emit (events.js:159:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\Jonathan Stroz\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:159:13)
13 verbose stack     at maybeClose (internal/child_process.js:943:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
14 verbose pkgid test@0.1.0
15 verbose cwd C:\Users\Jonathan Stroz\Documents\HackerNews-Production-master\src
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Jonathan Stroz\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
18 verbose node v9.2.0
19 verbose npm  v6.2.0
20 error code ELIFECYCLE
21 error errno 1
22 error test@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the test@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 ]

这是我的软件包配置

{
  "name": "test",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bluebird": "^3.5.1",
    "bootstrap": "^4.1.2",
    "minify": "^3.0.5",
    "netlify": "^1.2.0",
    "newsapi": "^2.2.2",
    "node-fetch": "^2.2.0",
    "react": "^16.4.1",
    "react-dom": "^16.4.1",
    "react-icons-kit": "^1.1.6",
    "react-popup": "^0.9.3",
    "react-scripts": "1.1.4",
    "react-select": "^1.2.1",
    "react-tabs-redux": "^3.0.2",
    "reactjs-popup": "^1.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

2 个答案:

答案 0 :(得分:1)

您可能正在使用旧版本的react-scripts,请尝试升级到react-scripts @> = 2.0.0

答案 1 :(得分:0)

您的其中一个依赖项似乎this line爆炸了。通过create-react-app仓库查看,我猜想他们在Webpack配置中传递给UglifyJS的选项不会解析ES2015 +。该newsapi软件包可能应该被Babelified来支持旧版本的Node和较旧的浏览器,因为通常人们不会Babelify他们的依赖项。

该软件包似乎也不适合浏览器使用,它似乎应该在服务器端使用。