我将 nodemon 安装到 devDependencies 并设置了脚本 "start" : "nodemon server.js"
。但是,当我执行 npm start
时,它会抛出此错误:
Error: Cannot find module 'C:\Users\win10\Desktop\nodemon\bin\nodemon.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! question-answer-rest-api@1.0.0 start: `nodemon server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the question-answer-rest-api@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
我的 package.json
{
"name": "question-answer-rest-api",
"version": "1.0.0",
"description": "Back end project for practice",
"main": "server.js",
"scripts": {
"start": "nodemon server.js"
},
"keywords": [
"Express",
"Nodejs",
"Mongoose",
"Api"
],
"author": "Cihan Özcan",
"license": "MIT",
"dependencies": {
"express": "^4.17.1"
},
"devDependencies": {
"nodemon": "^2.0.7"
}
}
我也填写了 server.js 并尝试了这种方式,但没有奏效。
我的 server.js 文件
const express = require('express');
const app = express();
const PORT = 5000
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`)
})
文件夹中没有任何文件。我在 SO 中找不到类似的错误。我将 nodemon 安装为 global 并检查了 pc 中的全局环境。没有问题。
有什么问题?
答案 0 :(得分:-2)
试试
npm uninstall nodemon
然后
npm install -g nodemon
应该有效