Javascript can';“t运行”;“新产品管理启动”;
这是我的package.json文件:Javascript can';“t运行”;“新产品管理启动”;,javascript,node.js,npm,Javascript,Node.js,Npm,这是我的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": { "ty
{
"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"
}
我该怎么办?顺便说一下,我有一个苹果
编辑:我按照你们的建议做了,并添加了脚本start,但现在当我运行“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
您需要在
脚本
下添加开始
脚本,即:
{
"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"
}
请尝试
npm run test
了解脚本
字段如何为包工作。json
您需要在脚本
下添加启动
脚本,并在本地节点服务器上承载或启动应用程序,添加命令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:运行命令npm start
时,确保您位于正确的项目目录中。文件index.js
和package.json
需要作为此项目目录的直接子项显示
项目结构:
martina
|- index.js
|- package.json
|- file1
|- file2
|- ...other files
...
在上面的项目结构中,martina
是主要的项目目录。在martina
内部,可以找到index.js
和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"
}
通过查看文件,将显示您的包。您刚刚创建了项目。您的index.js文件的目录似乎不正确。在package.json目录中创建index.js文件,然后运行node index.js或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
试试这个。你的解决方案会完成的。如果仍然出现错误,请让我知道重复:我相信
开始
需要位于package.json的脚本部分;现在您只有test
作为脚本。我将研究如何包含实际的开始脚本。这是否回答了您的问题@Martina,看看我答案的PS。你如何验证文件是否在正确的项目目录中?@Martina,看看PS。再次更新谢谢!我修好了!现在一切都已就绪,我得到一个错误:import React from'React'SyntaxError:Unexpected identifier。这似乎是一个错误。你知道为什么吗?你能接受这个答案并为你的错误提出一个新的问题,这样就很容易调试了。