[英]NPM module Is In /node_modules folder but cannot be found?
I am having a bit of an issue getting the md5
node module installed properly on an Ubuntu dev server I have setup.我在我设置的 Ubuntu 开发服务器上正确安装
md5
节点模块时遇到了一些问题。
(It works fine on my local windows machine, and I can install other modules with npm just fine on the dev server) (它在我的本地 Windows 机器上运行良好,我可以在开发服务器上使用 npm 安装其他模块就好了)
When I try and start a NodeJS application I am working on it fails stating that the md5
module is not installed.当我尝试启动一个 NodeJS 应用程序时,我正在处理它失败,表明未安装
md5
模块。
// trying to start my application that depends on md5.
drichardson@devwebserver:/var/www/node_app/meanapp$ node server.js
module.js:340
throw err;
^
Error: Cannot find module 'md5'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/www/node_app/node_modules/hashfile/index.js:7:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/www/node_app/meanapp/app/controllers/exchanges.server.controller.js:15:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
I have tried installing this within my working directory:我试过在我的工作目录中安装它:
// Installing in working directory
drichardson@devwebserver:/var/www/node_app/meanapp$ sudo npm install --save md5
npm http GET https://registry.npmjs.org/md5
npm http GET https://registry.npmjs.org/md5
npm http 304 https://registry.npmjs.org/md5
npm http GET https://registry.npmjs.org/is-buffer
npm http GET https://registry.npmjs.org/crypt
npm http GET https://registry.npmjs.org/charenc
npm http 304 https://registry.npmjs.org/crypt
npm http GET https://registry.npmjs.org/is-buffer
npm http GET https://registry.npmjs.org/charenc
npm http 200 https://registry.npmjs.org/is-buffer
npm http GET https://registry.npmjs.org/is-buffer/-/is-buffer-1.0.2.tgz
npm http GET https://registry.npmjs.org/is-buffer/-/is-buffer-1.0.2.tgz
npm http GET https://registry.npmjs.org/charenc
npm http GET https://registry.npmjs.org/charenc/-/charenc-0.0.1.tgz
npm http 200 https://registry.npmjs.org/charenc/-/charenc-0.0.1.tgz
npm http GET https://registry.npmjs.org/is-buffer/-/is-buffer-1.0.2.tgz
npm http 200 https://registry.npmjs.org/is-buffer/-/is-buffer-1.0.2.tgz
md5@2.0.0 node_modules/md5
├── charenc@0.0.1
├── crypt@0.0.1
└── is-buffer@1.0.2
Even though the node module shows up in my /node_modules folder, it still throws the "Cannot find module md5
"即使节点模块出现在我的 /node_modules 文件夹中,它仍然会抛出“找不到模块
md5
”
// MD5 In my node_modules folder:
drichardson@devwebserver:/var/www/node_app/meanapp/node_modules$ ls -la | grep 'md5'
drwxr-xr-x 2 drichardson drichardson 4096 Oct 30 13:53 md5
I have also tried:我也试过:
- Installing the module globally with "npm install -g md5" - 使用“npm install -g md5”全局安装模块
- Cleaning the Cache and Reinstalling "npm cache clean" - 清理缓存并重新安装“npm cache clean”
- Reinstalling the application with "npm install" - 使用“npm install”重新安装应用程序
What else can I try to get this so that npm recognizes md5 as being installed?我还能尝试什么来让 npm 识别出已安装的 md5?
Thanks,谢谢,
I had a similar issue and the problem wasn't where the module was installed, but instead it was because the main
property in the package.json
file was not correctly set.我遇到了类似的问题,问题不在于模块的安装位置,而是因为
package.json
文件中的main
属性设置不正确。 In my case it referred to a file that wasn't there.就我而言,它指的是一个不存在的文件。 Make sure that the
"main":"..."
is set correctly for the module.确保为模块正确设置了
"main":"..."
。
If this is a module that you do not control, as a quick fix you can make the change in the nearest node_modules directory.如果这是您无法控制的模块,作为快速修复,您可以在最近的 node_modules 目录中进行更改。 In our case this was located in the root of the project.
在我们的例子中,它位于项目的根目录中。
Can you try clearing entire node_modules and installing everything again?您可以尝试清除整个 node_modules 并重新安装所有内容吗?
rm -rf node_modules
npm install
In folder /var/www/node_app/node_modules/hashfile/在文件夹/var/www/node_app/node_modules/hashfile/
run npm install md5
运行
npm install md5
You tried this?你试过这个吗?
My problem ended up being the version of Node and NPM that I was running locally vs in my Docker containers.我的问题最终是我在本地运行的 Node 和 NPM 版本与在我的 Docker 容器中运行的版本不同。
# Local versions:
$ node --version
v12.18.2
$ npm --version
6.14.10
I changed in my Dockerfile
我改变了我的
Dockerfile
FROM node:15-alpine3.12
# ^^
# ...
to到
FROM node:12-alpine3.12
# ^^
# ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.