首页 > 解决方案 > “node server.js”工作,但“npm start”找不到节点

问题描述

在这里这里对类似问题的回答不能解决我的问题。

在一个空目录中,我创建了一个文件'server.js',它所做的只是一个console.log('hello')。使用“node server.js”运行此文件运行良好。但是在通过“npm start”运行的“npm init -y”之后给出:

npm start  
The system cannot find the path specified.

> prj@1.0.0 start E:\projects\prj
> node server.js

/bin/bash: node: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file bash
npm ERR! errno ENOENT
npm ERR! prj@1.0.0 start: `node server.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the prj@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 和 node 的正确版本。所有这一切都是在卸载/重新安装 node.js 之后发生的。

任何有关如何排除故障/修复的提示表示赞赏。

项目目录:

E:\prj
 package.json
 package-lock.json
 server.js   

package.json 是 npm init 之后的默认值:

{
 "name": "prj",
 "version": "1.0.0",
 "description": "",
 "main": "server.js",
 "scripts": {
   "test": "echo \"Error: no test specified\" && exit 1",
   "start": "node server.js"
   },
 "keywords": [],
 "author": "",
 "license": "ISC"
}

标签: node.jsnpm

解决方案


推荐阅读