Avose
Avose

Reputation: 11

npm run build - fails to compile despite development version working fine

I have a react app created with create-react-app, and npm run build is failing to compile a production build. It throws the following error:

$ npm run build

> [email protected] build C:\Users\User\Documents\Web_Projects\Portfolio\portfolio
> react-scripts build

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

Error: C:\Users\User\Documents\Web_Projects\Portfolio\portfolio\node_modules\c  lean-css\lib\options\format.js:1
  SyntaxError: Invalid or unexpected token

  - compileFunction

  - loader.js:1047 wrapSafe
    internal/modules/cjs/loader.js:1047:16

  - loader.js:1097 Module._compile
    internal/modules/cjs/loader.js:1097:27

  - loader.js:1153 Object.Module._extensions..js
    internal/modules/cjs/loader.js:1153:10

  - loader.js:977 Module.load
    internal/modules/cjs/loader.js:977:32

  - loader.js:877 Function.Module._load
    internal/modules/cjs/loader.js:877:14

  - loader.js:1019 Module.require
    internal/modules/cjs/loader.js:1019:19

  - helpers.js:77 require
    internal/modules/cjs/helpers.js:77:18

  - tidy-rules.js:1 Object.<anonymous>
    [portfolio]/[clean-css]/lib/optimizer/level-1/tidy-rules.js:1:14

  - loader.js:1133 Module._compile
    internal/modules/cjs/loader.js:1133:30


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!     C:\Users\User\AppData\Roaming\npm-cache\_logs\2020-11-06T14_23_18_276Z-debug.log

And the log file contains the following:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
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: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\User\Documents\Web_Projects\Portfolio\portfolio\node_modules\.bin;C:\Users\User\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\User\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\libnvvp;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\Calibre2;C:\Program Files\Microsoft SQL Server\120\Tools\Binn;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\NVIDIA Corporation\Nsight Compute 2019.5.0;C:\Program Files\nodejs;C:\Program Files\MATLAB\R2020a\runtime\win64;C:\Program Files\MATLAB\R2020a\bin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn;C:\Program Files\Microsoft SQL Server\120\DTS\Binn;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\texlive\2019\bin\win32;C:\Users\User\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\User\AppData\Roaming\npm;C:\Users\User\AppData\Local\Programs\Azure Data Studio\bin;C:\Program Files\heroku\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
9 verbose lifecycle [email protected]~build: CWD: C:\Users\User\Documents\Web_Projects\Portfolio\portfolio
10 silly lifecycle [email protected]~build: Args: [ '/d /s /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> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:310:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:310:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid [email protected]
15 verbose cwd C:\Users\User\Documents\Web_Projects\Portfolio\portfolio
16 verbose Windows_NT 10.0.19041
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
18 verbose node v12.16.3
19 verbose npm  v6.14.4
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 ]

npm start works fine, I can see the development build fine in the browser. But npm run build produces this error.

I've never encountered this error before and can't decipher anything from the error or logs that I could play with the try get it working. I can't even tell what's causing the error.

I've tried installing all my dependencies again with --save, and I've also tried clearing npm cache, but past that I can't think what else could be the problem.

Suggestions for where to look next are welcome!

Upvotes: 0

Views: 17448

Answers (1)

Avose
Avose

Reputation: 11

Looks like the node modules had become corrupt somewhere along the way. I deleted the node_modules folder and ran npm install and it was fixed.

Upvotes: 1

Related Questions