我正在关注 this YouTube教程系列,但是突然在运行服务器时遇到了这个问题 我尝试将节点重新卸载到最新的稳定版本。
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module 'D:\DATA\Learning\Creations\WEB\website\tabs tracker\Vue-and-Express.JS\server\scr\app.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
app.js代码
const express = require('express')
const bodyParser = require('body-parser')
const morgan = require('morgan')
const cors = require('cors')
const { sequelize } = require('./models')
const config = require('./config/config')
const app = express()
app.use(morgan('combined'))
app.use(bodyParser.json())
app.use(cors())
require('./routes')(app)
sequelize.sync().then(() => {
app.listen(config.port)
console.log(`Serverstarted on port ${config.port}`)
})
package.json
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "node ./node_modules/nodemon/bin/nodemon.js scr/app.js --exec \"npm run lint && node\"",
"lint": "./node_modules/.bin/eslint **/*.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"joi": "^17.2.0",
"morgan": "^1.10.0",
"sequelize": "^6.3.4",
"sqlite3": "^5.0.0"
},
"devDependencies": {
"eslint": "^7.7.0",
"nodemon": "^2.0.4",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-vue": "^6.2.2"
}
}
答案 0 :(得分:2)
我认为您在代码中的某个地方输入了'app'而不是/scr/app
答案 1 :(得分:1)
将scr/app.js
中的src/app.js
更改为package.json
答案 2 :(得分:0)
在使用 #vuejs 时遇到这个问题,我的解决方法是删除 package.lock.json 文件和 node_modules 文件夹。然后我运行 npm i 然后 npm run serve 运行良好