簡體   English   中英

NPM 模塊在 /node_modules 文件夾中但找不到?

[英]NPM module Is In /node_modules folder but cannot be found?

我在我設置的 Ubuntu 開發服務器上正確安裝md5節點模塊時遇到了一些問題。

(它在我的本地 Windows 機器上運行良好,我可以在開發服務器上使用 npm 安裝其他模塊就好了)

當我嘗試啟動一個 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)

我試過在我的工作目錄中安裝它:

    // 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

即使節點模塊出現在我的 /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

我也試過:

- 使用“npm install -g md5”全局安裝模塊
- 清理緩存並重新安裝“npm cache clean”
- 使用“npm install”重新安裝應用程序

我還能嘗試什么來讓 npm 識別出已安裝的 md5?

謝謝,

我遇到了類似的問題,問題不在於模塊的安裝位置,而是因為package.json文件中的main屬性設置不正確。 就我而言,它指的是一個不存在的文件。 確保為模塊正確設置了"main":"..."

如果這是您無法控制的模塊,作為快速修復,您可以在最近的 node_modules 目錄中進行更改。 在我們的例子中,它位於項目的根目錄中。

您可以嘗試清除整個 node_modules 並重新安裝所有內容嗎?

   rm -rf node_modules
   npm install

在文件夾/var/www/node_app/node_modules/hashfile/

運行npm install md5

你試過這個嗎?

我的問題最終是我在本地運行的 Node 和 NPM 版本與在我的 Docker 容器中運行的版本不同。

# Local versions:
$ node --version
v12.18.2
$ npm --version
6.14.10

我改變了我的Dockerfile

FROM node:15-alpine3.12
#         ^^
# ...

FROM node:12-alpine3.12
#         ^^
# ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM