Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

webpack - Using "npm run build" fails with "npm ERR! missing script: build"

How can i fix this error, I'm running Windows 10

When i try to npm run build on the cmd i get this error

C:Usersanai_> npm run build
npm ERR! missing script: build

Here is the log of the run

0 info it worked if it ends with ok
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' ]
2 info using npm@5.5.1
3 info using node@v9.1.0
4 verbose config Skipping project config: C:Usersanai_/.npmrc. (matches userconfig)
5 verbose stack Error: missing script: build
5 verbose stack     at run (C:Program Files
odejs
ode_modules
pmlib
un-script.js:151:19)
5 verbose stack     at C:Program Files
odejs
ode_modules
pmlib
un-script.js:61:5
5 verbose stack     at C:Program Files
odejs
ode_modules
pm
ode_modules
ead-package-json
ead-json.js:115:5
5 verbose stack     at C:Program Files
odejs
ode_modules
pm
ode_modules
ead-package-json
ead-json.js:402:5
5 verbose stack     at checkBinReferences_ (C:Program Files
odejs
ode_modules
pm
ode_modules
ead-package-json
ead-json.js:357:45)
5 verbose stack     at final (C:Program Files
odejs
ode_modules
pm
ode_modules
ead-package-json
ead-json.js:400:3)
5 verbose stack     at then (C:Program Files
odejs
ode_modules
pm
ode_modules
ead-package-json
ead-json.js:160:5)
5 verbose stack     at ReadFileContext.<anonymous> (C:Program Files
odejs
ode_modules
pm
ode_modules
ead-package-json
ead-json.js:332:20)
5 verbose stack     at ReadFileContext.callback (C:Program Files
odejs
ode_modules
pm
ode_modulesgraceful-fsgraceful-fs.js:78:16)
5 verbose stack     at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:437:13)
6 verbose cwd C:Usersanai_
7 verbose Windows_NT 10.0.15063
8 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "build"
9 verbose node v9.1.0
10 verbose npm  v5.5.1
11 error missing script: build
12 verbose exit [ 1, true ]

Although the error refers to a missing script build, i have placed a 'build' script in my package.json

{
  "name": "es6",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "build": "webpack"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^3.8.1"
  }

}

and this is my webpack.config.js file

module.exports = {
  entry: ['./app/index.js'],
  output: {
    path: './build',
    filename: 'bundle.js'

  }
}

Can anyone tell me how to fix this error or where it is coming from. I am new to using node.js, webpack and the command line. Thanks in advance for your time!

question from:https://stackoverflow.com/questions/47343658/using-npm-run-build-fails-with-npm-err-missing-script-build

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You put "npm run build && gh-pages -d build" in your deploy script, but you need to tell npm what to do when npm run build is being run. Configure build to whatever command needs to run to build your project.

Since you are using webpack, I assume it would be webpack --config webpack.conf.js. With gulp, gulp build, with TypeScript tsc -p tsproject.json, and so on. It depends on your project.

you can check out the full writeup here: https://github.com/npm/npm/wiki/Troubleshooting#a-brief-note-on-the-built-in-windows-configuration


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...