尝试使用npm start命令调试节点应用程序时收到此错误。
错误:
npm ERR!Windows_NT 6.3.9600 npm错误!argv“ C:\ Program Files \ nodejs \\ node.exe”“ C:\ Program Files \ nodejs \ node_modules \ npm \ bin \ npm-cli.js”“开始” npm ERR!节点v0.12.7 npm ERR!npm v2.11.3
npm ERR!缺少脚本:启动npm ERR!npm ERR!如果需要帮助,可以在以下位置报告此错误:npm ERR! https://github.com/npm/npm/issues npm错误!请在支持请求中包括以下文件:npm ERR!C:\ Users \ andrmoll.NORTHAMERICA \ Documents \ GitHub \ SVIChallenge \ npm-debug.log
从调试文件:
详细堆栈错误:缺少脚本:开始
运行时4个详细堆栈(C:\ Program Files \ nodejs \ node_modules \ npm \ lib \ run-script.js:142:19)
C:\ Program Files \ nodejs \ node_modules \ npm \ lib \ run-script.js:58:5处的4个详细堆栈
C:\ Program Files \ nodejs \ node_modules \ npm \ node_modules \ read-package-json \ read-json.js:345:5处的4个详细堆栈
在checkBinReferences_处的4个详细堆栈(C:\ Program Files \ nodejs \ node_modules \ npm \ node_modules \ read-package-json \ read-json.js:309:45)
最后有4个详细堆栈(C:\ Program Files \ nodejs \ node_modules \ npm \ node_modules \ read-package-json \ read-json.js:343:3)
当时的4个详细堆栈(C:\ Program Files \ nodejs \ node_modules \ npm \ node_modules \ read-package-json \ read-json.js:113:5)
C:\ Program Files \ nodejs \ node_modules \ npm \ node_modules \ read-package-json \ read-json.js:300:12的4个详细堆栈
evalmachine上的4个详细堆栈。:334:14
C:\ Program Files \ nodejs \ node_modules \ npm \ node_modules \ graceful-fs \ graceful-fs.js:102:5处的4个详细堆栈
FSReqWrap.oncomplete上的4个详细堆栈(evalmachine.:95:15)
看起来您可能尚未start
在package.json
文件中定义脚本,或者您的项目不包含server.js
文件。
如果软件包根目录中有一个server.js文件,则npm将默认启动命令传递给节点server.js。
https://docs.npmjs.com/misc/scripts#default-values
您可以将应用程序脚本的名称更改为server.js
或将以下内容添加到您的package.json
"scripts": {
"start": "node your-script.js"
}
或者......你可以只运行node your-script.js
直接
如果在package.json文件中添加了第二个“脚本”键,也会发生此错误。如果仅在package.json中保留一个“脚本”键,则错误消失。
就我而言,它没有用,因为我使用了"scripts"
两次。合并后-可以。
"scripts": {
"test": "make test",
"start": "node index.js"
}
第一次安装react-js时遇到了这个问题:这些行帮助我解决了这个问题:
npm rm -g create-react-app
npm install -g create-react-app
npx create-react-app my-app
来源:https : //stackoverflow.com/a/59260128/11652661
请在package.json中的脚本对象中使用以下代码行
"scripts": {
"start": "webpack-dev-server --hot"
}
对我来说,它工作得很好。
检查具有“ scripts”属性的package.json文件是否存在。如果不更新像这样的脚本属性
{
"name": "csvjson",
"version": "1.0.0",
"description": "upload csv to json and insert it into MongoDB for a single colletion",
"scripts": {
"start": "node csvjson.js"
},
"dependencies": {
"csvjson": "^4.3.4",
"fs": "^0.0.1-security",
"mongodb": "^2.2.31"
},
"devDependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/giturl.git"
},
"keywords": [
"csv",
"json",
"mongodb",
"nodejs",
"collection",
"import",
"export"
],
"author": "karthikeyan.a",
"license": "ISC",
"bugs": {
"url": "https://github.com/homepage/issues"
},
"homepage": "https://github.com/homepage#readme"
}
如果您正在使用babelify和watchify,请转到:
package.json
并将其添加到“脚本”中:
"scripts": {
"start": "watchify the-path-to-your-source-jsx-file -v -t [ babelify --presets [ react ] ] -o the-path-to-your-output-js-file"
}
一个例子是:
"scripts": {
"start": "watchify src/main.jsx -v -t [ babelify --presets [ react ] ] -o public/js/main.js"
}
感谢DevSlopes的Mark Price
就我而言,如果这是一个React项目,您可以尝试升级npm,然后再升级react-cli
npm -g install npm@version
npm install -g create-react-app
您可能安装了旧的(全局)npm安装导致了此问题。从12/19开始,npm不支持全局安装。
首先,使用以下方法卸载软件包:
npm uninstall -g create-react-app
某些osx / Linux用户可能还需要使用以下方法删除旧的npm:
rm -rf /usr/local/bin/create-react-app
现在,这是生成项目的唯一受支持的方法:
npx create-react-app my-app
最后,您可以运行:
npm start
应避免使用不稳定的npm版本。
我观察到一件事是基于npm版本的问题,npm版本4.6.1是稳定版本,但5.x不稳定,因为如果package.json是稳定版本,则在使用默认模板创建时package.json将被完美配置,因此我们手动不无需添加该脚本。
我在npm 5上遇到了以下问题,所以我降级到npm 4.6.1,然后它对我有用,
错误:尚不支持npm 5
看来您使用的是最近发布的npm 5。
不幸的是,创建React Native App不适用于npm 5。我们建议使用npm 4或yarn直到解决一些错误为止。
您可以通过以下网址了解npm 5的已知问题:https:
//github.com/npm/npm/issues/16991
Devas-MacBook-Air:SampleTestApp deva $ npm start npm错误!缺少脚本:开始
另一个可能的原因:在yarn中初始化项目时,您正在使用npm。(我自己做了)。因此它将yarn start
代替npm start
。
现在不建议在全局范围内安装create-react-app。而是通过执行以下操作来卸载全局安装的create-react-app软件包:npm uninstall -g create-react-app(如果此命令不起作用,则可能必须手动删除软件包文件夹。某些用户报告他们必须删除文件夹手动)
然后,您可以运行npx create-react-app my-app再次创建react应用。
参考:https : //github.com/facebook/create-react-app/issues/8086
请尝试以下步骤:
npm rm -g创建反应应用
npm install -g create-react-app
npx create-react-app我的应用
绝对可以!!
确保端口打开
var app = express();
app.set('port', (process.env.PORT || 5000));
BLAL BLA BLA,最后您已经拥有了
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'))
});
仍然是节点js中的新手,但这引起了更多这种情况。
看看您的client / package.json。你必须有这些脚本
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
"scripts": {
"prestart": "npm install",
"start": "http-server -a localhost -p 8000 -c-1"
}
将此代码段添加到package.json中,具体取决于您自己的配置。
我有同样的问题。我尝试如下在package.json文件中编写代码
"scripts": {
"start": "<your-script-file>.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
我已经解决了。它不是NPM错误,它与代理行为有关。
如果您落后于代理,
MAC
1. Goto System Preference (gears icon on your mac)
2. click your network
3. click advanced
4. click proxy
5. check excludes simple hostnames
6. add this line below (Bypass Proxy Settings...) "localhost, localhost:8080"
refer to the npm echo: "Project is running at http://localhost:8080/"
Windows
1. Goto your browser Proxy Settings (google it)
2. check Bypass local address
3. add this line below "localhost, localhost:8080"
文章标签:express , javascript , node.js , npm-scripts , package.json
版权声明:本文为原创文章,版权归 javascript 所有,欢迎分享本文,转载请保留出处!
评论已关闭!