你如何使用npm脚本运行一个js文件?

我不能让npm工作。 我的package.json文件有

"scripts": { "build": "build.js" } 

我有一个build.js文件在只是console.logs相同的文件夹。

当我跑步

 npm run build 

我得到错误

 The system cannot execute the specified program. npm ERR! Windows_NT 6.1.7601 npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build" npm ERR! node v4.1.1 npm ERR! npm v3.3.5 npm ERR! code ELIFECYCLE 

如果我移动build.js文件并将我的package.json文件更改为具有子文件夹

 "scripts": { "build": "build/build.js" } 

那么我得到的错误

 'build' is not recognized as an internal or external command, operable program or batch file. 

怎么了? 我正在复制示例文档 。

 { "scripts" : { "build": "node build.js"} } 

npm run buildnpm run-script build


 { "name": "build", "version": "1.0.0", "scripts": { "start": "node build.js" } } 

npm start


注意:你错过了{ brackets }和节点命令

文件夹结构很好:

 + build - package.json - build.js 

你应该使用npm run-script build或者npm build <project_folder> 。 更多信息在这里: https : //docs.npmjs.com/cli/build 。