我的 NPM 包中有以下文件:
package.json
:
{
"name": "npm-start",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
index.js
console.log('Hello world!');
当我尝试运行 npm start
时,我收到一条错误消息:
> npm start
npm ERR! missing script: start
好吧,这是真的:我在 "scripts"
对象中没有 "start"
属性。但是NPM's CLI Documentation关于 npm start
的声明:
If no
"start"
property is specified on the"scripts"
object, it will runnode server.js
.
为什么 NPM 让我失望了?在这种情况下不应该调用 node
吗?我错过了什么吗? (当然,手动调用 Node 也可以)。
如果它是相关的:
> npm -version
5.3.0
最佳答案
问题一打完,我就意识到自己的错误。
当 "start"
属性不存在时,NPM 将使用 server.js
调用 node
。但是我没有 server.js
。 NPM 在后台检查此 server.js
文件,如果不存在则失败。但理想情况下,NPM 应该报告未找到 server.js
。当前的处理方式令人困惑。
只要你有一个 server.js
文件,npm start
就可以正常工作。
关于node.js - `npm start` 提示 "missing script: start",没有运行 Node ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47219615/