简体   繁体   中英

Node can't find IP module

I am trying to use the IP module in a Node program. However, whenever I try to add it in using const ip = require("ip") , I get the following error:

internal/modules/cjs/loader.js:584
    throw err;
    ^

Error: Cannot find module 'ip'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/Users/fin444/Desktop/node/app.js:1:207)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)

Why is this happening? I have installed and reinstalled the latest version of IP several times globally on my computer, and all other Node modules work fine.

Try this:

  npm uninstall ip -g --save

Then:

  npm install ip -g --save

I don't know if --save is required anymore but I have had the issue that without this flag the module could not be found. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM