phanther phanther - 1 month ago 14
React JSX Question

Webpack fails when run through npm run

I'm trying to setup React. When I try to run

npm run webpack -p


It gives the following error.

npm ERR! Linux 4.4.0-43-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "webpack" "-i"
npm ERR! node v6.8.1
npm ERR! npm v3.10.8
npm ERR! file /home/phani/test/package.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! Trailing comma in object at 9:3
npm ERR! },
npm ERR! ^
npm ERR! File: /home/phani/test/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! Please include the following file with any support request:
npm ERR! /home/phani/test/npm-debug.log


And here is the error log,


0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'run', 'webpack', '-i' ]
2 info using npm@3.10.8
3 info using node@v6.8.1
4 verbose stack Error: Failed to parse json
4 verbose stack Trailing comma in object at 9:3
4 verbose stack },
4 verbose stack ^
4 verbose stack at parseError (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:390:11)
4 verbose stack at parseJson (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:79:23)
4 verbose stack at /usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:48:5
4 verbose stack at /usr/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
4 verbose stack at tryToString (fs.js:455:3)
4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12)
5 verbose cwd /home/phani/test
6 error Linux 4.4.0-43-generic
7 error argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "webpack" "-i"
8 error node v6.8.1
9 error npm v3.10.8
10 error file /home/phani/test/package.json
11 error code EJSONPARSE
12 error Failed to parse json
12 error Trailing comma in object at 9:3
12 error },
12 error ^
13 error File: /home/phani/test/package.json
14 error Failed to parse package.json data.
14 error package.json must be actual JSON, not just JavaScript.
14 error
14 error This is not a bug in npm.
14 error Tell the package author to fix their package.json file. JSON.parse
15 verbose exit [ 1, true ]



I tried installing webpack globally. Still the error persist.

Answer

Npm doesn't recognize webpack as it's one of the dependencies, and not an NPM script.

If you want to install webpack locally (the preferred method) - In your package.json add a script:

"scripts": {
   "build": "webpack -p"
}

Then run it using npm run build.

If you want to use the globally installed webpack - run it using webpack -p (without npm run).

Comments