[ERR_MODULE_NOT_FOUND] 是啥意思?
Posted
技术标签:
【中文标题】[ERR_MODULE_NOT_FOUND] 是啥意思?【英文标题】:What does [ERROR_MODULE_NOT_FOUND] mean?[ERR_MODULE_NOT_FOUND] 是什么意思? 【发布时间】:2022-01-10 18:08:01 【问题描述】:运行“nodemon server”后,我得到了这个错误:
[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server index.js`
internal/process/esm_loader.js:74
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/brandonkim/Desktop/restaurant-reviews/backend/server.js' imported from /Users/brandonkim/Desktop/restaurant-reviews/backend/index.js
at finalizeResolution (internal/modules/esm/resolve.js:271:11)
at moduleResolve (internal/modules/esm/resolve.js:694:10)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:805:11)
at Loader.resolve (internal/modules/esm/loader.js:88:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:241:28)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:72:40)
at link (internal/modules/esm/module_job.js:71:36)
code: 'ERR_MODULE_NOT_FOUND'
[nodemon] app crashed - waiting for file changes before starting...
这是什么意思?我如何解决它?我只是想为网站的后端运行服务器。
我的 package.json 是:
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts":
"test": "echo \"Error: no test specified\" && exit 1"
,
"keywords": [],
"author": "",
"license": "ISC",
"dependencies":
"body-parser": "^1.19.0",
"bson": "^4.2.2",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"mongodb": "^3.6.4"
【问题讨论】:
脚本index.js
找不到server.js
脚本。
【参考方案1】:
那是因为您启动了应用程序
node server index.js
该命令被识别为
node server.js index.js.
直接改成
node index
或 node index.js
或 nodemon index.js
真正添加扩展名 .JS 是可选的
【讨论】:
我实际上使用的是“nodemon server”。 node index 或 node index.js 或 nodemon index.js 也不起作用 当你运行 node index 你得到什么错误?以上是关于[ERR_MODULE_NOT_FOUND] 是啥意思?的主要内容,如果未能解决你的问题,请参考以下文章