NPM is giving me an Error with every command - javascript

Whenever I'm running a command with npm. it's giving an Error. A few days ago, It was totally fine. I used it in some of my projects but now it is can't do nothing.
node:internal/modules/cjs/loader:941
const err = new Error(message);
^
Error: Cannot find module '../../package.json'
Require stack:
- C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\lib\utils\unsupported.js
- C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\lib\cli.js
- C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
at Function.Module._load (node:internal/modules/cjs/loader:774:27)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\lib\utils\unsupported.js:2:19)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Module.require (node:internal/modules/cjs/loader:1013:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\nuur hassan\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\utils\\unsupported.js',
'C:\\Users\\nuur hassan\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js',
'C:\\Users\\nuur hassan\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js'
]
}

The error says that npm can't find the package.json file. Make sure you haven't deleted it. If you want to create one you can use npm init to initialize one in the current directory. Even if that fails I'd reinstall node js and double check the NODE_PATH.

Related

Can't find module "semver" on node.js / code: 'MODULE_NOT_FOUND',

I'm having trouble running a project. He always falls into this error. What can it be?
node:internal/modules/cjs/loader:956
const err = new Error(message);
^
Error: Cannot find module 'semver'
Require stack:
- /usr/share/nodejs/npm/lib/utils/unsupported.js
- /usr/share/nodejs/npm/lib/cli.js
- /usr/share/nodejs/npm/bin/npm-cli.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> (/usr/share/nodejs/npm/lib/utils/unsupported.js:2:16)
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 Module.require (node:internal/modules/cjs/loader:1028:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/share/nodejs/npm/lib/utils/unsupported.js',
'/usr/share/nodejs/npm/lib/cli.js',
'/usr/share/nodejs/npm/bin/npm-cli.js'
]
}
I have already reinstalled and installed npm several times. I cleared cache and everything and nothing!

Discord JS - Error: Cannot find module 'node:events' on node v16.14.0

I am currently using node v16.14.0 as per the title and getting this error:
Error: Cannot find module 'node:events'
Require stack:
- /Users/username/bp/bp-website/backend/node_modules/discord.js/src/client/BaseClient.js
- /Users/username/bp/bp-website/backend/node_modules/discord.js/src/index.js
- /Users/username/bp/bp-website/backend/discord/bot.js
- /Users/username/bp/bp-website/backend/discord/purchase.js
- /Users/username/bp/bp-website/backend/webserver.js
- /Users/username/bp/bp-website/backend/index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/Users/username/bp/bp-website/backend/node_modules/discord.js/src/client/BaseClient.js:3:22)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/username/bp/bp-website/backend/node_modules/discord.js/src/client/BaseClient.js',
'/Users/username/bp/bp-website/backend/node_modules/discord.js/src/index.js',
'/Users/username/bp/bp-website/backend/discord/bot.js',
'/Users/username/bp/bp-website/backend/discord/purchase.js',
'/Users/username/bp/bp-website/backend/webserver.js',
'/Users/username/bp/bp-website/backend/index.js'
]
}
I have looked at other questions, however, they all say upgrade to Node v16.6 which I downgraded to to test but also still didn't work. Any help would be greatly appreciated!
Run node -v in the terminal. If the output is v16.6.0 or higher, you're good to go, because the required version of discord.js is v16.6.0 or higher. Click here to read full documentation from discord.js .
Without the latest version of node.js you might get errors like:
1.Unexpected token '?'
2.Cannot find module: 'node:events'
const client = new Discord.Client({ intents: ["DIRECT_MESSAGES", "GUILD_MESSAGES"] });
instead of:
const client = new Discord.Client();

How to fix "Error: Module build failed: Error: Cannot find module '#angular/localize/src/tools/src/extract/extraction'" in Angular?

I tried to test the i18n features described in https://angular.io/guide/i18n#localizing-your-app but I cannot run the i18n extractor because it cannot be found.
I am using:
node v14.17.6
npm v6.14.15
ng v12.2.5
I wanted to add an example project here, but due to corporate network restrictions I am unable to push it to GitHub... So, what I did was:
run ng new ng-i18n-test
run cd ng-i18n-test
run ng add #angular/localize
replace the contents of app.component.html with <p i18n>Hello World</p>
run ng extract-i18n
That leads to the following error:
./src/main.ts - Error: Module build failed: Error: Cannot find module '#angular/localize/src/tools/src/extract/extraction'
Require stack:
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\build-angular\src\extract-i18n\ivy-extract-loader.js
- C:\workspace\ng-i18n-test\node_modules\webpack\lib\ProgressPlugin.js
- C:\workspace\ng-i18n-test\node_modules\webpack\lib\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\build-webpack\src\webpack\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\build-webpack\src\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\build-angular\src\extract-i18n\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\architect\node\node-modules-architect-host.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\architect\node\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\models\architect-command.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\commands\extract-i18n-impl.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\schematics\tools\export-ref.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\schematics\tools\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\utilities\json-schema.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\models\command-runner.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\lib\cli\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\lib\init.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\bin\ng
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (C:\workspace\ng-i18n-test\node_modules\#angular-devkit\build-angular\src\extract-i18n\ivy-extract-loader.js:29:22)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
./src/polyfills.ts - Error: Module build failed (from ./node_modules/#angular-devkit/build-angular/src/extract-i18n/ivy-extract-loader.js):
Error: Cannot find module '#angular/localize/src/tools/src/extract/extraction'
Require stack:
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\build-angular\src\extract-i18n\ivy-extract-loader.js
- C:\workspace\ng-i18n-test\node_modules\loader-runner\lib\loadLoader.js
- C:\workspace\ng-i18n-test\node_modules\loader-runner\lib\LoaderRunner.js
- C:\workspace\ng-i18n-test\node_modules\webpack\lib\NormalModuleFactory.js
- C:\workspace\ng-i18n-test\node_modules\webpack\lib\Compiler.js
- C:\workspace\ng-i18n-test\node_modules\webpack\lib\ProgressPlugin.js
- C:\workspace\ng-i18n-test\node_modules\webpack\lib\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\build-webpack\src\webpack\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\build-webpack\src\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\build-angular\src\extract-i18n\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\architect\node\node-modules-architect-host.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\architect\node\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\models\architect-command.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\commands\extract-i18n-impl.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\schematics\tools\export-ref.js
- C:\workspace\ng-i18n-test\node_modules\#angular-devkit\schematics\tools\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\utilities\json-schema.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\models\command-runner.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\lib\cli\index.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\lib\init.js
- C:\workspace\ng-i18n-test\node_modules\#angular\cli\bin\ng
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (C:\workspace\ng-i18n-test\node_modules\#angular-devkit\build-angular\src\extract-i18n\ivy-extract-loader.js:29:22)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
Frankly, I am not sure what went wrong. It is was is written in the i18n guide. What went wrong?
It works on a different machine. I guess there has to be an issue with my machine... Great. I'll check my setup.
Edit yep, it was a bad setup. Not sure what the issue was. I created a new one using the steps above and it works now.

Cannot find module

internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'better-sqlite3'
Require stack:
- D:\UserProfile\Users\Administrator\Desktop\rosbot\src\utils\db.js
- D:\UserProfile\Users\Administrator\Desktop\rosbot\src\Client.js
- D:\UserProfile\Users\Administrator\Desktop\rosbot\app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (D:\UserProfile\Users\Administrator\Desktop\rosbot\src\utils\db.js:1:18)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'D:\\UserProfile\\Users\\Administrator\\Desktop\\rosbot\\src\\utils\\db.js',
'D:\\UserProfile\\Users\\Administrator\\Desktop\\rosbot\\src\\Client.js',
'D:\\UserProfile\\Users\\Administrator\\Desktop\\rosbot\\app.js'
]
}
I am getting this error when I am trying to run the discord bot with vscode by the command "node ." and I don't know how to solve this
Looks like you haven't Imported the module or named it wrong or installed
example to fix importing error:
const <name> = require("better-sqlite3");
example to fix name error:
const <name> = require("better-sqlite3");
example to fix installing error:
in cmd type: npm i better-sqlite3
after that type
const <name> = require("better-sqlite3")
change name with what you want it to be as.

Error: Cannot find module '#rails/webpacker' rails 6

When I run my Rails 6.0 application on development environment I get the next trace on the development.log
[Webpacker] Compiling…
[Webpacker] Compilation failed:
/home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:93
throw err;
^
Error: Cannot find module '#rails/webpacker'
Require stack:
- /mnt/config/webpack/environment.js
- /mnt/config/webpack/development.js
- /home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js
- /home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js
- /home/alejo/rails_project/node_modules/webpack/bin/webpack.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:954:17)
at Function.Module._load (internal/modules/cjs/loader.js:847:27)
at Module.require (internal/modules/cjs/loader.js:1016:19)
at require (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at Object.<anonymous> (/mnt/config/webpack/environment.js:1:87)
at Module._compile (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
at Module.load (internal/modules/cjs/loader.js:976:32)
at Function.Module._load (internal/modules/cjs/loader.js:884:14)
at Module.require (internal/modules/cjs/loader.js:1016:19)
at require (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at Object.<anonymous> (/mnt/config/webpack/development.js:3:21)
at Module._compile (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
at Module.load (internal/modules/cjs/loader.js:976:32)
at Function.Module._load (internal/modules/cjs/loader.js:884:14)
at Module.require (internal/modules/cjs/loader.js:1016:19)
at require (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at WEBPACK_OPTIONS (/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:114:13)
at requireConfig (/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:116:6)
at /home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:123:17
at Array.forEach (<anonymous>)
at module.exports (/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js:121:15)
at /home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:71:45
at Object.parse (/home/alejo/rails_project/node_modules/webpack-cli/node_modules/yargs/yargs.js:567:18)
at /home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:49:8
at Object.<anonymous> (/home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js:366:3)
at Module._compile (internal/modules/cjs/loader.js:1121:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
at Module.load (internal/modules/cjs/loader.js:976:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/mnt/config/webpack/environment.js',
'/mnt/config/webpack/development.js',
'/home/alejo/rails_project/node_modules/webpack-cli/bin/utils/convert-argv.js',
'/home/alejo/rails_project/node_modules/webpack-cli/bin/cli.js',
'/home/alejo/rails_project/node_modules/webpack/bin/webpack.js'
]
}
I am using webpacker 4.0.7, rails 6.0.0 and ruby 2.6.5
I want to know why am I getting this error and how do I solve it.
Thank you
I ran into this issue as well. For me, the issue was the node version (13.6.0). I figured this out by running yarn add #rails/webpacker, which returned the error Expected version "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7". Got "13.6.0"
To fix it:
Update node to an appropriate version (see error above)
Delete node_modules directory
Update yarn files with yarn install --check-files
Install webpacker with rails webpacker:install
Confirm it worked by bin/webpack-dev-server and getting no errors

Categories

Resources