node.js 命令 `npm start` 什么都不做
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25997681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Command `npm start` does nothing
提问by hawkharris
After entering npm startin the directory of my Node project, I see the spinning pipe symbol to show that npm is loading. However, this graphic is displayed indefinitely and nothing happens. No error messages are provided. How can I fix or at least diagnose this issue?
进入npm start我的 Node 项目目录后,我看到了旋转管道符号,表明 npm 正在加载。但是,此图形会无限期地显示,并且没有任何反应。没有提供错误消息。我该如何解决或至少诊断此问题?
My package.jsonis as follows:
我的package.json如下:
{
"name": "Project_Name",
"version": "0.0.1",
"private": true,
"main": "./bin/www",
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"express": "~4.2.0",
"static-favicon": "~1.0.0",
"morgan": "~1.0.0",
"cookie-parser": "~1.0.1",
"body-parser": "~1.0.0",
"debug": "~0.7.4",
"jade": "~1.3.0",
"request": "~2.39.0",
"oauth-1.0a": "~0.1.1",
"passport": "~0.2.0",
"express-session": "~1.7.2",
"passport-local": "~1.0.0",
"connect-flash": "~0.1.1"
}
}
I suspected that missing dependencies could be a problem, but that doesn't seem to be an issue. I ran the npm-install-missingmodule and got the following results:
我怀疑缺少依赖项可能是一个问题,但这似乎不是问题。我运行了npm-install-missing模块并得到以下结果:


回答by hawkharris
The problem had to do with dependencies. First, I installed the npm-install-missingmodule to see the app's dependencies:
问题与依赖关系有关。首先,我安装了npm-install-missing模块以查看应用程序的依赖项:
npm install -g npm-install-missing
npm install -g npm-install-missing
With the module installed, I could run it to see which dependencies needed to be updated:
安装模块后,我可以运行它以查看需要更新哪些依赖项:
npm-install-missing
npm-install-missing
The results are shown as a screenshot in my question above. You'll notice that express-session, crypto-jsand passportare in red. I needed to install the expected version of each of these modules:
结果在我上面的问题中显示为屏幕截图。你会注意到express-session,crypto-js和passport是红色的。我需要安装每个模块的预期版本:
npm install -g [email protected]
npm install -g [email protected]
npm install -g [email protected]
npm install -g [email protected]
npm install -g [email protected]
npm install -g [email protected]
After installing the dependencies, I ran npm startagain. The app appeared on localhost:3000.
安装依赖项后,我npm start再次运行。该应用程序出现在localhost:3000。
回答by Mohamed Ben HEnda
1- You must install connect and server-static modules
1-您必须安装连接和服务器静态模块
npm install connect serve-static
2- You must create server.js file that contains:
2- 您必须创建 server.js 文件,其中包含:
var connect = require('connect');
var serveStatic = require('serve-static');
connect().use(serveStatic(__dirname)).listen(8000);
3- Run your command:
3-运行您的命令:
node server
4- for testing add a HTML file (index.html) in your nodejs directory
4- 为了测试在你的 nodejs 目录中添加一个 HTML 文件 (index.html)
5- Open the browser and put :
5-打开浏览器并输入:
http://localhost:8000/index.html
http://localhost:8000/index.html
the server is running and your page html is dipalyed
服务器正在运行,您的页面 html 已显示
回答by Ramy M. Mousa
After several uninstalland installto nodeand npmthe problem was that I set ignore-scripts=truein .npmrcat ~/directory
经过多次uninstall和install于node和npm问题是,我将ignore-scripts=true在.npmrc在~/目录
so to solve this:
所以要解决这个问题:
nano ~/.npmrc
remove the line ignore-scripts=trueor change it to be
删除该行ignore-scripts=true或将其更改为
ignore-scripts=false
This solved my problem after about an hour of trying different extreme solutions.
在尝试不同的极端解决方案大约一个小时后,这解决了我的问题。
回答by Neeraj Kumar
Actually whenever you run npm start,
其实每当你跑步时npm start,
it runs a package's "start" script, if one was provided. If no version is specified, then it starts the "active" version.
它运行包的“启动”脚本(如果提供)。如果未指定版本,则它启动“活动”版本。
So, npm looks into your package.jsonfile which should be having something like
所以,npm 查看你的package.json文件,它应该有类似的东西
"start": "webpack-dev-server --hot"
“开始”:“webpack-dev-server --hot”
then it will do that. If npm can't find your start script, it defaults to:
然后它会这样做。如果 npm 找不到您的启动脚本,则默认为:
node server.js
节点服务器.js
回答by ashwath hegde
I had the similar issue i tried all the above methods but did not work then i noticed that there was node_module folder in my project pathwhich was not belonging to this project . it got installed long back by mistake . once i deleted that particular folder then my react project started to work
我遇到了类似的问题,我尝试了上述所有方法,但没有奏效,然后我注意到我的项目路径中有node_module 文件夹,它不属于该项目。它被错误地安装了很久。一旦我删除了那个特定的文件夹,我的反应项目就开始工作了
回答by Hamfri
Run this command from your console npm config set ignore-scripts falseor sudo npm config set ignore-scripts false. This applies to linux or mac users.
从您的控制台npm config set ignore-scripts false或sudo npm config set ignore-scripts false. 这适用于 linux 或 mac 用户。

