【发布时间】:2019-04-13 18:29:06
【问题描述】:
我正在尝试使用 npm start 命令,但我的 package.json 中没有正确的 "start" 脚本。谁能告诉我正确的添加方法吗?
我尝试将 "start": "node server.js" 添加到 package.json 中的脚本中,但这会引发错误:
> 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"
}
【问题讨论】:
-
找不到C:\Users\Aristophanes\server.js,因为没有server.js。你想从什么开始?
-
能否分享您的目录结构。只要您的 package.json 旁边有一个 server.js 文件,这应该可以按照您的描述工作。
标签: node.js npm npm-scripts