Error: Cannot find module, Nodemon crashes
Error: Cannot find module, Nodemon crashes
我是 NodeJS 和 Express 的新手。我听说过 nodemon 并试图 运行 它。但是得到一个错误。我尝试了 github 的解决方案,但似乎没有任何效果。
当我 运行 node app.js
它工作正常,甚至 localhost:3000
响应它。
但特别是 nodemon 似乎不起作用。我已经全局安装了。
当我说我访问了所有具有此问题解决方案的 Whosebug 页面时,请相信我。但是 none 似乎有效。我重新安装了 Nodejs。我已经重装 node_modules 很多次了。
并尝试按照这些页面上的说明更改 package.json 中的 scripts{}
。
{
"name": "prac-mysql",
"version": "1.0.0",
"description": "Connecting MySQL NODEjs",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"faker": "^4.1.0",
"mysql": "^2.18.1",
"nodemon": "^2.0.3"
}
}
以上是最初的代码。请帮我。非常感谢。
(我在windows系统上使用它)
从您的屏幕截图中我可以看出您正在使用 minGW。在他们的官方 website 上写着:
MinGW may have problems with paths containing spaces, and if not,
usually other programs used with MinGW will experience problems with
such paths. Thus, we strongly recommend that you do not install MinGW
in any location with spaces in the path name reference. You should
avoid installing into any directory or subdirectory having names like
"Program Files" or "My Documents", etc.
所以这可能不是 nodemon
本身的问题,而是路径的基础解析问题。尝试使用不带空格的不同目录名称或从 cmd/powershell.
执行 nodemon
编辑:
问题是您 运行 nodemon
没有指定任何文件,它会尝试查找您在 [=27= 中设置的 main
文件].由于您已将其设置为 index.js
并且此类文件不存在,因此该命令失败。将 package.json 中的 main
更改为 app.js
应该可以解决问题。
我是 NodeJS 和 Express 的新手。我听说过 nodemon 并试图 运行 它。但是得到一个错误。我尝试了 github 的解决方案,但似乎没有任何效果。
当我 运行 node app.js
它工作正常,甚至 localhost:3000
响应它。
但特别是 nodemon 似乎不起作用。我已经全局安装了。
当我说我访问了所有具有此问题解决方案的 Whosebug 页面时,请相信我。但是 none 似乎有效。我重新安装了 Nodejs。我已经重装 node_modules 很多次了。
并尝试按照这些页面上的说明更改 package.json 中的 scripts{}
。
{
"name": "prac-mysql",
"version": "1.0.0",
"description": "Connecting MySQL NODEjs",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"faker": "^4.1.0",
"mysql": "^2.18.1",
"nodemon": "^2.0.3"
}
}
以上是最初的代码。请帮我。非常感谢。
(我在windows系统上使用它)
从您的屏幕截图中我可以看出您正在使用 minGW。在他们的官方 website 上写着:
MinGW may have problems with paths containing spaces, and if not, usually other programs used with MinGW will experience problems with such paths. Thus, we strongly recommend that you do not install MinGW in any location with spaces in the path name reference. You should avoid installing into any directory or subdirectory having names like "Program Files" or "My Documents", etc.
所以这可能不是 nodemon
本身的问题,而是路径的基础解析问题。尝试使用不带空格的不同目录名称或从 cmd/powershell.
编辑:
问题是您 运行 nodemon
没有指定任何文件,它会尝试查找您在 [=27= 中设置的 main
文件].由于您已将其设置为 index.js
并且此类文件不存在,因此该命令失败。将 package.json 中的 main
更改为 app.js
应该可以解决问题。