nodemon 应用程序崩溃:错误代码 - MODULE_NOT_FOUND,requiresstack:[]

nodemon app crashed : Error code- MODULE_NOT_FOUND, requirestack: [ ]

当我 运行ning nodemon 运行 启动时出现以下错误 我在 macOS 上 运行ning 这个。不确定这是否重要。 错误

node:internal/modules/cjs/loader:926
  throw err;
  ^

Error: Cannot find module '/Users/jarvis/Documents/Backend/mongoTelusko/run'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:923:15)
    at Function.Module._load (node:internal/modules/cjs/loader:768:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
[nodemon] app crashed - waiting for file changes before starting...

这是我的app.js文件

const express = require('express')
const mongoose = require('mongoose')
const url = 'mongodb://localhost/AlienDBex'

    enter code here

const app = express()

mongoose.connect(url, {useNewUrlParser: true})
const con = mongoose.connection

con.on('open', function(){
    console.log('Connected...')
})

这是我的package.json文件

{
  "name": "mongotelusko",
  "version": "1.0.0",
  "main": "app.js",
  "scripts": {
    "start": "nodemon app.js"
  },
  "author": "malay",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1",
    "mongodb": "^3.6.5",
    "mongoose": "^5.12.2"
  },
  "devDependencies": {
    "nodemon": "^2.0.7"
  },
  "description": ""
}

你是 运行 nodemon run start,它告诉 nodemon 使用参数 start 执行 run (run.js)。您是要使用 npm run start 吗?提示:您也可以使用 npm start 作为快捷方式。

"scripts": {
    "start": "nodemon app.js"
  }, 

由于您在 package.json 中指定了“启动”脚本,npm start 命令会自动调用 nodemon app.js 但是,您也可以手动 运行 nodemon app.js 也有相同的效果。

错误:nodemon 运行启动
正确:nodemon app.jsnpm start

我在尝试 运行 我的 Mac 上的代码时遇到了同样的错误。

我找到了它向我显示此错误的原因:

  • 第一个原因是我通过从 [nodejs.org][1] 下载的安装包安装了 Node.js,但我应该从 航站楼.

  • 第二个原因是我发现我正试图 运行 来自不同文件夹的文件。我在文件夹 /users/practice/file-manager/frontend 中 - 试图 运行 位于目录 /users/practice/file-manager/backend 中的文件中的代码 - 导致此错误的主要原因。

作为对我有用的解决方案:

  • 确保您已经从终端
  • 安装了Node.js
  • 确保在尝试 运行 .js 文件时位于正确的目录中。

也许这些信息对您有帮助。

我在尝试新文件等后的解决方案...没有用。那么从头开始:

  • 删除 node.js 并清除有关 npm 的缓存(来自 appdata)
  • 创建新文件并确定路径,您可以使用 'cd'
  • 确认
  • 正在尝试 re-install npm_modules 在我的项目文件夹中。(npm install)

然后成功了。