[英]can't run "npm start"
this is my package.json file:这是我的 package.json 文件:
{
"name": "martina",
"version": "1.0.0",
"description": "d",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "d"
},
"author": "",
"license": "ISC"
}
what should I do?我应该怎么办? I have a Mac by the way!
顺便说一下,我有一台 Mac!
EDIT: I did what you guys recommended and added the script start, but now when I run 'npm start' I get this:编辑:我做了你们推荐的并添加了脚本启动,但是现在当我运行“npm start”时,我得到了这个:
> martina@1.0.0 start /Users/martina
> node index.js
internal/modules/cjs/loader.js:589
throw err;
^
Error: Cannot find module '/Users/martina/index.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:303:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! martina@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the martina@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! /Users/martina/.npm/_logs/2020-06-11T08_05_28_654Z-debug.log
You need to add a start
script under scripts
, ie:您需要在 scripts 下添加
start
scripts
,即:
{
"name": "martina",
"version": "1.0.0",
"description": "d",
"main": "index.js",
"scripts": {
"start": "echo STARTING...",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "d"
},
"author": "",
"license": "ISC"
}
Try npm run test
to get an idea of how the scripts
field works for package.json
.尝试
npm run test
以了解scripts
字段如何为package.json
工作。
You need to add a start
script under scripts
, and to host or start the application on local node server, add the command node index.js
as the value for start
script.您需要在 scripts 下添加一个
start
scripts
,并在本地节点服务器上托管或启动应用程序,添加命令node index.js
作为start
脚本的值。
{
"name": "martina",
"version": "1.0.0",
"description": "d",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "d"
},
"author": "",
"license": "ISC"
}
PS: While running the command npm start
, make sure that you are in the correct project directory. PS:运行命令
npm start
,请确保您位于正确的项目目录中。 The file index.js
and package.json
needs to be present as the direct childs of this project directory.文件
index.js
和package.json
需要作为该项目目录的直接子项存在。
Project Structure:项目结构:
martina
|- index.js
|- package.json
|- file1
|- file2
|- ...other files
...
See in the above project structure, martina
is the main project directory.在上面的项目结构中看到,
martina
是项目的主目录。 And inside martina
, index.js
and package.json
can be found.在
package.json
里面,可以找到index.js
和martina
。
{
"name": "martina",
"version": "1.0.0",
"description": "d",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "d"
},
"author": "",
"license": "ISC"
}
Your package appears by looking at the file.您的 package 通过查看文件出现。 That you have just created the project.
您刚刚创建了项目。 It seems that the directory of your index.js file in not correct.
看来你的 index.js 文件的目录不正确。 you create the index.js file in the package.json directory itself, after that run the node index.js or npm start command
您在 package.json 目录本身中创建 index.js 文件,然后运行节点 index.js 或 npm 启动命令
> martina@1.0.0 start /Users/martina
> node index.js
internal/modules/cjs/loader.js:589
throw err;
^
Error: Cannot find module '/Users/martina/index.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:303:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! martina@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the martina@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! /Users/martina/.npm/_logs/2020-06-11T08_05_28_654Z-debug.log
Try this one.试试这个。 Your solution will be done.
您的解决方案将完成。 If you still get an error then let me know
如果您仍然遇到错误,请告诉我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.