当我运行、nodemon、、running时,它给了我以下错误,我正在macos上运行它。不确定这是否重要。误差
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": ""
}
发布于 2021-06-02 21:55:53
"scripts": {
"start": "nodemon app.js"
},
由于您已经在package.json中指定了"start“脚本,因此npm start
命令会自动调用nodemon app.js
,因此您也可以手动运行nodemon app.js
,这也具有相同的效果。
错:没有恶魔跑开始
正确:nodemon app.js
或npm start
发布于 2021-03-24 21:20:24
您正在运行nodemon run start
,它告诉nodemon
使用参数start
执行run
(run.js)。你是有意使用npm run start
的吗?提示:您还可以使用npm start
作为快捷方式。
发布于 2021-12-15 08:14:16
当我试图在我的Mac上运行代码时,我也遇到了同样的错误。
我发现了为什么它要向我显示这个错误:
/users/practice/file-manager/frontend
中--试图从位于/users/practice/file-manager/backend
目录中的文件中运行代码--这是导致此错误的主要原因。作为一种对我有效的解决方案:
当您试图运行terminal
.js
安装了Node.js,确定您位于正确的目录中。也许这些信息对你有帮助。
https://stackoverflow.com/questions/66789133
复制相似问题