node.js - `npm start` 提示 "missing script: start",没有运行 Node

标签 node.js npm

我的 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 run node 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/

相关文章:

javascript - 抓取亚马逊品牌页面

node.js - Node.js安装gulp时出错

node.js - chromedriver 安装失败

javascript - Node.js 读取并执行 Ruby 文件?

node.js - 无法全局安装 express

android - Google 登录 - 尝试访问用户信息时出现 401 错误 "Login Required"

javascript - 如何从字符串中提取硬盘序列号

node.js - npm install <git> 与开发依赖项

javascript - 使 Visual Studio Code IDE 识别 Javascript 中的 EJS 变量

Node.js 从应用程序内运行 MongoDB