3

I have finished my react application that was created with create-react-app , i have no issues running on local with npm start but when i try to build using npm-build

i get an error on minifying the code. I have tried cloning my project and trying to build it, i have tried creating a test project and trying npm build and am having no problems with it, it is only when i try to build my full project.

this is my error

> 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.

this my error file

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 ]

this is my package config

{
  "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"
  }
}
Jonathan Stro
  • 99
  • 2
  • 6

2 Answers2

5

you're likely using an old version of react-scripts,try upgrading to react-scripts@>=2.0.0

Bruce Wang
  • 47
  • 1
  • 4
3

It seems to be blowing up on this line of one of your dependencies. Looking through the create-react-app repo, I would guess that the options they're passing to UglifyJS in their Webpack config don't parse ES2015+. That newsapi package should probably be Babelified to support older versions of Node and older browsers, since usually folks don't Babelify their dependencies.

That package also doesn't seem to be browser-friendly, it looks like it's something that should be used server-side.

Zac Anger
  • 6,983
  • 2
  • 15
  • 42
  • Thank you so much for the help! Do you think another solution would be to use http requests for the newsapi instead of doing it through the npm package? – Jonathan Stro Jul 23 '18 at 01:39
  • That would be a good solution! If you're running your own server for this app, you could also use the newsapi package on the server so you wouldn't have to redo some of that author's work. – Zac Anger Jul 23 '18 at 01:40
  • You can also try adding/modifying *a transpilation step* of your own, before minification (e.g. add `node_modules/newsapi` to the `include` list of your `babel-loader` config, if using webpack + babel). – Janaka Bandara Jan 22 '21 at 03:17