命令`npm start`什么都不做

haw*_*ris 3 node.js npm

进入npm start我的Node项目目录后,我看到旋转管道符号显示npm正在加载.但是,此图形无限期显示,没有任何反应.没有提供错误消息.我该如何修复或至少诊断此问题?

我的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"
  }
}
Run Code Online (Sandbox Code Playgroud)

我怀疑缺少依赖可能是一个问题,但这似乎不是一个问题.我运行npm-install-missing模块并得到以下结果:

在此输入图像描述

Ram*_*usa 10

经过多次uninstallinstallnodenpm问题是,我将ignore-scripts=true.npmrc~/目录

所以要解决这个问题:

nano ~/.npmrc
Run Code Online (Sandbox Code Playgroud)

删除该行ignore-scripts=true或将其更改为

ignore-scripts=false
Run Code Online (Sandbox Code Playgroud)

在尝试不同的极端解决方案大约一个小时后,这解决了我的问题。


Moh*_*nda 6

1-您必须安装connect和server-static模块

npm install connect serve-static
Run Code Online (Sandbox Code Playgroud)

2-您必须创建包含以下内容的server.js文件:

var connect = require('connect');
var serveStatic = require('serve-static');
connect().use(serveStatic(__dirname)).listen(8000);
Run Code Online (Sandbox Code Playgroud)

3-运行命令:

node server
Run Code Online (Sandbox Code Playgroud)

4-用于测试在nodejs目录中添加HTML文件(index.html)

5-打开浏览器并输入:

http://localhost:8000/index.html

服务器正在运行,您的页面html被重复分析


haw*_*ris 5

问题与依赖关系有关.首先,我安装了npm-install-missing模块以查看应用程序的依赖项:

npm install -g npm-install-missing

安装模块后,我可以运行它来查看需要更新的依赖项:

npm-install-missing

结果显示在我上面的问题中的屏幕截图中.你会注意到express-session,crypto-js并且passport是红色的.我需要安装每个模块的预期版本:

npm install -g express-session@1.7.6

npm install -g crypto-js@3.1.2

npm install -g passport@0.2.1

安装依赖项后,我npm start再次运行.该应用程序出现了localhost:3000.


Ham*_*fri 5

从您的控制台npm config set ignore-scripts falsesudo npm config set ignore-scripts false. 这适用于 linux 或 mac 用户。