node:internal/modules/cjs/loader:1047 const err = new Error(message); - node.js

After installing nodejs on my windows 10 machine, when I try to use npm, I get this error
node:internal/modules/cjs/loader:1047
const err = new Error(message);
^
Error: Cannot find module '../package.json'
Require stack:
- C:\Users\Mfoniso\AppData\Roaming\npm\node_modules\npm\lib\cli.js
- C:\Users\Mfoniso\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1047:15)
at Module._load (node:internal/modules/cjs/loader:893:27)
at Module.require (node:internal/modules/cjs/loader:1113:19)
at require (node:internal/modules/cjs/helpers:103:18)
at createEnginesValidation (C:\Users\Mfoniso\AppData\Roaming\npm\node_modules\npm\lib\cli.js:7:15)
at module.exports (C:\Users\Mfoniso\AppData\Roaming\npm\node_modules\npm\lib\cli.js:78:27)
at Object.<anonymous> (C:\Users\Mfoniso\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js:2:25)
at Module._compile (node:internal/modules/cjs/loader:1226:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
at Module.load (node:internal/modules/cjs/loader:1089:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\Mfoniso\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js',
'C:\\Users\\Mfoniso\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js'
]
}
Node.js v18.14.0
I have uninstalled and reinstalled but this issue still persist

It look's like there is a missing file, the package.json, in the npm installation. The issue could be due to the corruption in the npm. You can try to re-install the npm:
Delete the existing npm folder located at C:\Users\Mfoniso\AppData\Roaming\npm.
Run this command to re-install the npm: npm install -g npm
If the issue still persists, you can just uninstall both Node.js and npm and re-install Node.js again.

Code: MODULE_NOT_FOUND, you need install the module...
npm I cjs
Or:
npm i cjs#latest
If you intalled the module, erase

Related

How do I fix npm ERR! code ERR_SSL_CIPHER_OPERATION_FAILED when creating electron or react app

This issue is hindering my time a lot, I tried many solutions I found in the web, from reinstalling node js, installing the new openssl version, reinstalling git bash (console), allowed gitbash and nodejs through firewall, and even FORMATTED THE WHOLE PC. Nothing worked, Please help me as soon as possible.
error below
npm WARN exec The following package was not found and will be installed: create-electron-app#6.0.5
npm ERR! code ERR_SSL_CIPHER_OPERATION_FAILED
npm ERR! 7C020000:error:1C800066:Provider routines:ossl_gcm_stream_update:cipher operation failed:c:\ws\deps\openssl\openssl\providers\implementations\ciphers\ciphercommon_gcm.c:320:
npm ERR!
after running it again I get this error:
module.exports = bind.call(Function.call, Object.prototype.hasOwnProperty);
TypeError: bind.call is not a function
at Object.<anonymous> (C:\Users\Keba\AppData\Local\npm-cache\_npx\36f5f21e8c68ce75\node_modules\has\src\index.js:5:23)
at Module._compile (node:internal/modules/cjs/loader:1275:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
at Module.load (node:internal/modules/cjs/loader:1133:32)
at Module._load (node:internal/modules/cjs/loader:972:12)
at Module.require (node:internal/modules/cjs/loader:1157:19)
at require (node:internal/modules/helpers:119:18)
at Object.<anonymous> (C:\Users\Keba\AppData\Local\npm-cache\_npx\36f5f21e8c68ce75\node_modules\#electron-forge\cli\node_modules\is-core-module\index.js:3:11)
at Module._compile (node:internal/modules/cjs/loader:1275:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
Node.js v19.6.1

node:internal/modules/cjs/loader:1056 throw err;

I am using Node.js v19.4.0.
When I run npx create-react-app MyApp to create react project
in visual studio code editor I get the following error:
node:internal/modules/cjs/loader:1056
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1053:15)
at Module._load (node:internal/modules/cjs/loader:898:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:84:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v19.4.0
node:internal/modules/cjs/loader:1056
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npx-cli.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1053:15)
at Module._load (node:internal/modules/cjs/loader:898:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:84:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
the first solution is to uninstall the node.js and npm and then reinstall them.
or it might be because of an incorrect node_modules path. please check the path and make sure it is correct.
Downgrade to a lts supported version!
brew install node#18
brew link --overwrite node#18
node --version
worked for me. (Macbook M1; Ventura 13.1.)
First, try to clear npm cache:
npm cache clear --force or npm cache clean --force
then remove all node_modules from the application
remove the package-lock.json file from the application
Install packages again by using this command npm install
then start application using npm start
If the above solution will not work then, try to remove node.js and then re-install.
Hope this helps!

How to resolve "Cannot find module './common/helpers'" error when trying to install solcjs globally with npm?

I'm running into an issue while trying to install the Solidity compiler locally through npm. After running npm i -g solc and checking for installation by running any commands such as solcjs --help, I receive the following error:
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module './common/helpers'
Require stack:
- /usr/local/lib/node_modules/solc/linker.js
- /usr/local/lib/node_modules/solc/translate.js
- /usr/local/lib/node_modules/solc/wrapper.js
- /usr/local/lib/node_modules/solc/index.js
- /usr/local/lib/node_modules/solc/solc.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object.<anonymous> (/usr/local/lib/node_modules/solc/linker.js:7:19)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/local/lib/node_modules/solc/linker.js',
'/usr/local/lib/node_modules/solc/translate.js',
'/usr/local/lib/node_modules/solc/wrapper.js',
'/usr/local/lib/node_modules/solc/index.js',
'/usr/local/lib/node_modules/solc/solc.js'
]
}
I tried a variety of things including checking my NODE_PATH, manual installation from the solc-js GitHub, and trying to run the command with npx. However, none of these helped with the above error. For additional context, I am running on macOS Monterey. Would greatly appreciate any help regarding this.
According to this: https://github.com/ethereum/solc-js/issues/624, this is a bug introduced in 0.8.14.
It's going to be fixed in 0.8.15, in the meantime you can downgrade to 0.8.13 to avoid this.
I think it has to do with the version, I had to uninstall the current version
npm uninstall solc
npm install --save solc#0.4.25
Worked for my 2 friends (MAC M1 & W10) and me
npm uninstall solc —global
npm install —save solc#0.8.13 —global

node express module not found when installed globally

my node app directory sits at /usr/node/express-test/app.js
I followed this thread to set up my environment so that I can have a freelancer come in and install npm packages globally on our server without having to have access to sudo.
How to npm install globally without root
I've checked my NODE_PATH... looks okay to me.
echo $NODE_PATH
/usr/node/.npm-packages/lib/node_modules
However, the error I see when I try to run my app.js appears to be that it cannot find my globally installed express module
app.js
/usr/node/express-test# node app.js
internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module 'express'
Require stack:
- /usr/node/express-test/app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/usr/node/express-test/app.js:2:15)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/usr/node/express-test/app.js' ]
}
Ideas to what the problem may be please?
My suggestions on this:
First of all, do not install express or any other packages as global put packages in the package.json and run npm install or do npm install --save express to save the packages to local node_modules and list it in package.json, track that package.json & package-lock.json in git so that it can be used in other places, this way if you shift to some new VM you don't need to install packages as global again, you can just do npm install or better npm ci and it's all work.
Secondly, if you still want to use global packages go to /usr/node/.npm-packages/lib/node_modules and see if you can find express folder there

React Native CLI, Cannot find module '/usr/local/lib/node_modules/react-native-cli/node_modules/prompt/lib/prompt'

I'm having a problem installing the react native CLI
When I run react-native init or any other cli method
internal/modules/cjs/loader.js:296
throw err;
^
Error: Cannot find module '/usr/local/lib/node_modules/react-native-cli/node_modules/prompt/lib/prompt'. Please verify that the package.json has a valid "main" entry
at tryPackage (internal/modules/cjs/loader.js:288:19)
at Function.Module._findPath (internal/modules/cjs/loader.js:515:18)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:759:27)
at Function.Module._load (internal/modules/cjs/loader.js:677:27)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/usr/local/lib/node_modules/react-native-cli/index.js:43:14)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32) {
code: 'MODULE_NOT_FOUND',
path: '/usr/local/lib/node_modules/react-native-cli/node_modules/prompt/package.json',
requestPath: 'prompt'
}
Removed and re-installed using npm install -g react-native-cli but no luck.
node version v12.10.0,
npm version 6.10.3
This was resolved by completely removing Node and re-installing using homebrew
I was resolved by removing node and remove this folder /usr/local/lib/node_modules/react-native-cli/node_modules/ and reinstall node
run command (yarn add npm) if you have yarn
I have resolved my issue with this command

Resources