错误:internal/modules/cjs/loader.js:968 throw err; node 模块?

5
我正在跟随 这个 YouTube 教程系列,但在运行服务器时突然遇到了这个问题。我尝试重新卸载 node 到最新的稳定版本。
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"
  }
}


1
你能运行 npm install 吗? - Karl L
如果您的 package.json 与 app.js 在同一个目录中,则需要删除 "scr/",只需将 app.js 留在那里。 - Karl L
是的,我也试过了,但是没有起作用 @KarlL - Shadow
得到相同的错误? - Karl L
更改了但仍然存在同样的问题,我应该清除缓存吗? - Shadow
显示剩余4条评论
3个回答

2

我认为你的代码中有个错别字,你导入'app'时使用了/scr/app而不是src/app


1

在你的package.json中将scr/app.js更改为src/app.js


0

使用 #vuejs 时遇到了这个问题,对我而言解决方案是删除 package.lock.json 文件和 node_modules 文件夹。然后运行 npm i 命令,接着运行 npm run serve 就可以正常工作了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接