NPM启动脚本丢失

时间:2018-11-10 11:14:13

标签: node.js npm npm-scripts

我正在尝试使用npm start命令,但是我的 package.json 中没有正确的“开始” 脚本。谁能告诉我正确的添加方式?

我尝试在 package.json 中的脚本中添加“ start”:“ node server.js” ,但这会引发错误:

> node server.js

internal/modules/cjs/loader.js:589
    throw err;
    ^

Error: Cannot find module 'C:\Users\Aristophanes\server.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:15)
    at Function.Module._load (internal/modules/cjs/loader.js:513:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
    at startup (internal/bootstrap/node.js:308:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:878:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! aristophanes@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the aristophanes@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Aristophanes\AppData\Roaming\npm-cache\_logs\2018-11-10T11_34_37_097Z-debug.log

因此找不到 server.js 文件。谁能详细说明我应该在哪个文件中添加到“开始”脚本中? Package.json

{
  "name": "aristophanes",
  "version": "1.0.0",
  "description": "",
  "main": ".eslintrc.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "author": "",
  "license": "ISC"
}

1 个答案:

答案 0 :(得分:0)

尝试在package.json中更改"main": "server.js"

编辑:您必须将文件名定义为main,其中包含您的server.listen回调。另外,您可以从node [your-server-file].js开始运行。如果您的文件名为index.js,节点会自动找到它,则不需要main部分。