internal/modules/cjs/loader.js:584 issue - npm

I got a problem when I input any npm cmd, it says
internal/modules/cjs/loader.js:584
Operating System: Windows 10 64bit
What shall I do to solve this issue?
internal/modules/cjs/loader.js:584
throw err;
^
Error: Cannot find module 'E:\FED\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

For many people on Mac (not sure about Windows/Linux), the solution is:
Delete node_modules and package-lock.json, then run $ npm install again.
You can also try updating your version of node.
Check version with $ node -v,
install with $ sudo n stable

I was having a similar error but it was because I hadn't had my node_modules(the ones you deleted ) file open in the file I was working on, even though I had run npm Install.
my Error was
Cannot find module _resolveFilename

If you build and deploy another place at a later time for example in an docker image, it may help to bundle the dependencies that the loader cannot find in package.json. Then the packaged are bundled and the loader can find them.
"bundledDependencies": [ "express", "express-http-proxy", ],
"dependencies": { ...}

Before starting any project you have to write this command npm init --yes

Related

How to fix unexpected token in ESLint?

I install ESLint globally using the command npm install -g eslint on my Mac. It was successful installing, but when I run eslint -v this is the issue I encounter:
$ npm install -g eslint
path/to/bin/eslint -> path/to/lib/node_modules/eslint/bin/eslint.js
+ eslint#7.3.1
added 107 packages from 63 contributors in 4.823s
$ eslint -v
path/to/lib/node_modules/eslint/bin/eslint.js:93
} catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
I would like to know what are the missing steps that cause this issue? I'm using Node.js v8.16.2 and NPM v6.4.1.
The error happens because } catch { is a relatively recent (ES2019) language feature called "optional catch binding"; prior to its introduction, binding the caught error (e.g. } catch (err) {) was required syntactically. Per node.green, you need at least Node 10 to have that language feature.
So why does this happen in ESLint? Per e.g. the release blog, version 7 has dropped support for Node 8; they're no longer testing against that version and more modern language features will be assumed to be supported.
To fix it, either:
Upgrade Node (Node 8 is out of LTS, which is why ESLint dropped support); or
npm install eslint#6 (with -g if you want to install globally) to use the older version of ESLint with Node 8 support.
In case it's helpful for anyone, I had a slightly different twist on the other answer. In my case, the error was happening during the Travis CI build process and causing it to fail. The solution in my case was to update my .travis.yml file to node_js: "16"

React install problems with npm

When I run npx create-react-app, I had these errors. Maybe someone knows whats it's wrong? P.S. also had tried npm-install -g create-react-app.
C:\Users\Deividas\Desktop\PAMEGINIMAS>create-react-app my-app
internal/modules/cjs/loader.js:621
throw e;
^
Error: No valid exports main found for 'C:\Users\Deividas\AppData\Roaming\npm\node_modules\create-react-app\node_modules\is-promise'
at resolveExportsTarget (internal/modules/cjs/loader.js:618:9)
at applyExports (internal/modules/cjs/loader.js:499:14)
at resolveExports (internal/modules/cjs/loader.js:548:12)
at Function.Module._findPath (internal/modules/cjs/loader.js:650:22)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:948:27)
at Function.Module._load (internal/modules/cjs/loader.js:854:27)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\Deividas\AppData\Roaming\npm\node_modules\create-react-app\node_modules\run-async\index.js:3:17)
at Module._compile (internal/modules/cjs/loader.js:1128:30) {
code: 'MODULE_NOT_FOUND'
}
This seems to be a recent problem with npm. There is an issue open as of the last few hours and it seems like people are working on it. I don't think it's anything to do with yourproject.
The issue
While the issue is being fixed: try installing node version 12.12.0 as shown below (if using nvm) and run create-react-app again.
nvm install 12.12.0
nvm use 12.12.0
I'd try to clear your cache npm cache clean --force. What version of node and npm are you using?

Fix "Cannot find module 'libnpx' " on react-native init

With a fresh project, after running react-native init {project},
during the phase "Installing required Cocoapods dependencies", this error is thrown:
Error: Cannot find module 'libnpx'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:649:15)
at Function.Module._load (internal/modules/cjs/loader.js:575:25)
at Module.require (internal/modules/cjs/loader.js:705:19)
at require (internal/modules/cjs/helpers.js:14:16)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npx-cli.js:3:13)
at Module._compile (internal/modules/cjs/loader.js:799:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:810:10)
at Module.load (internal/modules/cjs/loader.js:666:32)
at tryModuleLoad (internal/modules/cjs/loader.js:606:12)
at Function.Module._load (internal/modules/cjs/loader.js:598:3)
(node:27038) UnhandledPromiseRejectionWarning: Error: Failed to install CocoaPods dependencies for iOS project, which is required by this template.
Please try again manually: "cd ./RNimage/ios && pod install".
Following the suggestion to run pod install, the same error is thrown in addition to
[!] Invalid 'Podfile' file 767: unexpected token at ''.
# from /Users/.../Desktop/Development/RNproject/ios/Podfile:42
# -------------------------------------------
#
> use_native_modules!
# end
# -------------------------------------------
I haven't even touched the project why is this happening and how do i fix it?
Before this i ran sudo chown -R 501:20 "/Users/vorousjames/.npm". I dont know if thats significant to this issue but it has broken alot.
In my case, I just updated nodejs using sudo n stable. After a successful upgrade, it showed the warning that the executable path for node has changed and I need to restart the current shell. I forgot to restart the shell, and got this error message. It worked fine after restarting.
No need to delete any files as for the above issue.
So, to fix the problem just install the node from:
https://nodejs.org/en/
I had to reset the shell location hash with "hash -r"
deleted node & npm files from usr/local/bin then re-installed node LTS version. npm commands work now
Try install libnpx using the following command :
npm i libnpx
It worked for me : )

karma start Cannot find module 'jasmine-core'

I was getting the following error when I ran "karma start"
module.js:340
throw err;
^
Error: Cannot find module 'jasmine-core'
at Function.Module._resolveFilename (module.js:338:15)
at Function.require.resolve (module.js:384:19)
at initJasmine (/usr/lib/node_modules/karma-jasmine/lib/index.js:8:42)
at Array.invoke [as 0] (/usr/lib/node_modules/karma/node_modules/di/lib/injector.js:75:15)
at get (/usr/lib/node_modules/karma/node_modules/di/lib/injector.js:48:43)
at /usr/lib/node_modules/karma/lib/server.js:137:20
at Array.forEach (native)
at Server._start (/usr/lib/node_modules/karma/lib/server.js:136:21)
at invoke (/usr/lib/node_modules/karma/node_modules/di/lib/injector.js:75:15)
at Server.start (/usr/lib/node_modules/karma/lib/server.js:101:18)
at Object.exports.run (/usr/lib/node_modules/karma/lib/cli.js:231:26)
at Object. (/usr/lib/node_modules/karma/bin/karma:3:23)
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)
Does anyone know why this is happening? I was running karma in a VM. I tried several npm install commands and nothing worked. After I shutdown my machine for the night and came back the next day the problem went away and everything is working again. So, I'm not blocked anymore.. Anyone have some thoughts on what could be happening?
I solved using npm install jasmine-core --save-dev
try install jasmine-core globally (Jasmine on NPM).
use npm install -g jasmine-core
Even with karma and karma-jasmine installed in the local project's node_modules you must still npm install jasmine.
So for a fresh Karma project:
npm install karma karma-jasmine jasmine to install the required modules locally.
Optionally add --save-dev to write to your package.json.
Note these do not need to be -g globally installed here.
karma start
This step requires you to have Karma installed globally (sudo npm install -g karma).
Navigate to folder:
cd node_modules\karma-jasmine
Run:
npm install
This should download the required dependencies and fix the issue.
Also, it is important to know the installation path where do you have karma.conf.js file.
I have this problem, and have tried every suggestion on the page without it fixing the problem. Well, I haven't yet rebooted, so I'll try that next, but I have closed my shell (git-bash) and re-opened it in case it was an environment variable problem. Something is wrong here and I don't think the problem has been identified yet.

yeoman generator fails: "Cannot find module 'download'"

I've uninstalled and reinstalled yo and download using npm. And switched to node 10.28 and node 11.14 but when I try and run a yo generator I keep getting:
module.js:333
throw err;
^
Error: Cannot find module 'download'
at Function.Module._resolveFilename (module.js:331:15)
at Function.Module._load (module.js:273:25)
at Module.require (module.js:357:17)
at require (module.js:373:17)
at Object.<anonymous> (/usr/local/share/npm/lib/node_modules/yo/node_modules/yeoman-generator/lib/actions/fetch.js:5:16)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
at Function.Module._load (module.js:305:12)
at Module.require (module.js:357:17)
I tried uninstalling / re-installing npm, yeoman, node, and the generator, plus googling and trying random things - nothing seemed to help.
Solution:
After some time fiddling - this fixed it:
cd /usr/local/share/npm/lib/
npm i download && npm update
Reinstall the latest version?
I don't know what went wrong here, but a module is missing. It might be because of the way you're changing the node version (it might change the path to node modules). Or it might be an installation error, make sure to read through the npm install logs.
I had this same problem on a version of node that I installed with brew and then upgraded (several months later) using brew upgrade node. I fixed it by running brew uninstall --force node to remove all the versions of node and then running brew install node and npm install -g yo generator-kraken bower grunt-cli again. This may have happened as a result of having multiple versions of node installed, as reported by brew when I attempted to unistall node the first time (output below).
brew uninstall node
Uninstalling /usr/local/Cellar/node/4.2.1... (2738 files, 36M)
node 0.10.29 is still installed.
Remove them all with `brew uninstall --force node`.
"npm i download" never worked for me at all. With "npm install -g download" I solved definitely my problem followed, as suggested, by "npm update".