简体   繁体   English

命令 `npm start` 什么都不做

[英]Command `npm start` does nothing

After entering npm start in the directory of my Node project, I see the spinning pipe symbol to show that npm is loading.在我的 Node 项目目录中输入npm start后,我看到旋转管道符号表示 npm 正在加载。 However, this graphic is displayed indefinitely and nothing happens.但是,此图形会无限期地显示,并且没有任何反应。 No error messages are provided.没有提供错误消息。 How can I fix or at least diagnose this issue?我该如何解决或至少诊断此问题?

My package.json is 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-missing module and got the following results:我运行了npm-install-missing模块并得到以下结果:

在此处输入图片说明

After several uninstall and install to node and npm the problem was that I set ignore-scripts=true in .npmrc at ~/ directory几次uninstallinstallnodenpm ,问题是我在~/目录的.npmrc中设置了ignore-scripts=true

so to solve this:所以要解决这个问题:

nano ~/.npmrc

remove the line ignore-scripts=true or change it to be删除行ignore-scripts=true或将其更改为

ignore-scripts=false

This solved my problem after about an hour of trying different extreme solutions.在尝试不同的极端解决方案大约一个小时后,这解决了我的问题。

The problem had to do with dependencies.问题与依赖关系有关。 First, I installed the npm-install-missing module to see the app's dependencies:首先,我安装了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

The results are shown as a screenshot in my question above.结果在我上面的问题中显示为屏幕截图。 You'll notice that express-session , crypto-js and passport are in red.您会注意到express-sessioncrypto-jspassport是红色的。 I needed to install the expected version of each of these modules:我需要安装每个模块的预期版本:

npm install -g express-session@1.7.6

npm install -g crypto-js@3.1.2

npm install -g passport@0.2.1

After installing the dependencies, I ran npm start again.安装依赖项后,我再次运行npm start The app appeared on localhost:3000 .该应用程序出现在localhost:3000

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

the server is running and your page html is dipalyed服务器正在运行,您的页面 html 已显示

Run this command from your console npm config set ignore-scripts false or sudo npm config set ignore-scripts false .从您的控制台npm config set ignore-scripts falsesudo npm config set ignore-scripts false运行此命令。 This applies to linux or mac users.这适用于 linux 或 mac 用户。

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.json file 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

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 path which was not belonging to this project .我遇到了类似的问题,我尝试了上述所有方法,但没有奏效,然后我注意到我的项目路径中有node_module 文件夹,它不属于该项目。 it got installed long back by mistake .它被错误地安装了很久。 once i deleted that particular folder then my react project started to work一旦我删除了那个特定的文件夹,我的反应项目就开始工作了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM