简体   繁体   中英

MODULE_NOT_FOUND Error, after successfully installing a npm module - require(module);

I get a MODULE_NOT_FOUND error after successfully installing the external module "file" with npm. It appears in the project folder with all its files as usual, the dependencies in the json file are also there. It happens with every npm package. I already reinstalled npm and tried different LTS versions of npm. I double checked the json file that the dependencies are corret.

This is the error message:

 phila@DESKTOP-68STT9S MINGW64 /g/My Drive/Work - Software/WebDevelopmentCourse/Web Development/introNPMNODE $ node test.js node:internal/modules/cjs/loader:959 throw err; ^ Error: Cannot find module 'file' Require stack: - G:\My Drive\Work - Software\WebDevelopmentCourse\Web Development\introNPMNODE\test.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15) at Function.Module._load (node:internal/modules/cjs/loader:804:27) at Module.require (node:internal/modules/cjs/loader:1028:19) at require (node:internal/modules/cjs/helpers:102:18) at Object.<anonymous> (G:\My Drive\Work - Software\WebDevelopmentCourse\Web Development\introNPMNODE\test.js:1:12) at Module._compile (node:internal/modules/cjs/loader:1126:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10) at Module.load (node:internal/modules/cjs/loader:1004:32) at Function.Module._load (node:internal/modules/cjs/loader:839:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) { code: 'MODULE_NOT_FOUND', requireStack: [ 'G:\\My Drive\\Work - Software\\WebDevelopmentCourse\\Web Development\\introNPMNODE\\test.js' ] }

This is the json file:

 { "name": "intronpmnode", "version": "1.0.0", "description": "test", "main": "test.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "phil", "license": "ISC", "dependencies": { "core-util-is": "^1.0.3", "file": "^0.2.2" } }

the javascript "test.js" file:

 var file = require("file");

make sure you are pointing the node command to a file that exists on your file system, delete node_modules and package-lock.json , re-install dependencies and restart your IDE.

If the error is not resolved, try to delete your and (not) files, re-run and restart your IDE. node_modules package-lock.json package.json npm install

delete node_modules and package-lock.json

rm -rf node_modules

rm -f package-lock.json

clean npm cache

npm cache clean --force

npm install

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