I am trying to take under input in nodejs using prompt but it shows me the following error:
node:internal/modules/cjs/loader:998
throw err;
^
Error: Cannot find module 'prompt-sync'
Require stack:
- D:\Code\C++\Concepts\conditionals.js
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (D:\Code\C++\Concepts\conditionals.js:1:16)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'D:\\Code\\C++\\Concepts\\conditionals.js' ]
}
I have installed 'prompt-sync' using npm but the issue still persists.
This is my code:
const prompt = require('prompt-sync')();
let num = prompt("Enter your age: ");
console.log(typeof num);
I have tried restarting my pc and updated nodejs to its latest version(currently 9.2.0).
Any kind of help will be appreciated.
Clean your installed node modules like so:
npm cache verify
rm -rf node_modules
rm package-lock.json
npm i
rm works if you are under linux or gitbash on Windows. If not delete the node_modules folder and the package.lock.json. (not the package.json)
When executing the npm i, take a look if error messages comes. Not all npm packages are combatiple with all node versions.
Controll in your package.json if the prompt-sync module is in the dependency section. If not reinstall it. You need to be inside your project folder when you install a module.
Related
First time posting, please be gentle...
Trying to follow along with Kevin Powell tutorial on setting up gulp to automate some SCSS compiling etc - link below
https://www.youtube.com/watch?v=QgMQeLymAdU&t=633s
Fairly confident I followed the instructions correctly but when trying to run the gulp style command I'm getting the following error.
node_modules seems to be set up correctly in the root folder when installed and package.json has gulp in the dependencies as well.
Any help would be fantastic.
Error: Cannot find module 'gulp;'
Require stack:
- C:\Users\Admin\OneDrive\Desktop\test\gulpfile.js
- C:\Users\Admin\AppData\Roaming\npm\node_modules\gulp\node_modules\gulp-cli\lib\shared\require-or-import.js
- C:\Users\Admin\AppData\Roaming\npm\node_modules\gulp\node_modules\gulp-cli\lib\versioned\^3.7.0\index.js
- C:\Users\Admin\AppData\Roaming\npm\node_modules\gulp\node_modules\gulp-cli\index.js
- C:\Users\Admin\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (C:\Users\Admin\OneDrive\Desktop\test\gulpfile.js:1:14)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\Admin\\OneDrive\\Desktop\\test\\gulpfile.js',
'C:\\Users\\Admin\\AppData\\Roaming\\npm\\node_modules\\gulp\\node_modules\\gulp-cli\\lib\\shared\\require-or-import.js',
'C:\\Users\\Admin\\AppData\\Roaming\\npm\\node_modules\\gulp\\node_modules\\gulp-cli\\lib\\versioned\\^3.7.0\\index.js',
'C:\\Users\\Admin\\AppData\\Roaming\\npm\\node_modules\\gulp\\node_modules\\gulp-cli\\index.js',
'C:\\Users\\Admin\\AppData\\Roaming\\npm\\node_modules\\gulp\\bin\\gulp.js'
]
}
Tried deleting node_modules and npm install againw it the same issues.
If you have any previously installed gulp globally, Uninstall them using the below command :
run npm rm --global
and then try running the below and install gulp-cli globally:
npm install --global gulp-cli
And then go to your project directory and run the below command:
npm install --save-dev gulp
Please find the official gulp documentation here
We've got some error and we try to install optionator but nothing happened. We're using Linux
We're trying to npm i from package.json which include this dependencies
"optionalDependencies": {
"eslint-config-<name>": "github:<username>/<repo>"
}
then we tried to run npm i optionator but still get the same error
Error: Cannot find module 'optionator'
Require stack:
- /usr/share/nodejs/eslint/lib/options.js
- /usr/share/nodejs/eslint/lib/cli.js
- /usr/share/nodejs/eslint/bin/eslint.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
at Function.Module._load (internal/modules/cjs/loader.js:730:27)
at Module.require (internal/modules/cjs/loader.js:957:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/usr/share/nodejs/eslint/lib/options.js:12:20)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Module.require (internal/modules/cjs/loader.js:957:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/share/nodejs/eslint/lib/options.js',
'/usr/share/nodejs/eslint/lib/cli.js',
'/usr/share/nodejs/eslint/bin/eslint.js'
Anyone who experienced this, please help us. Thanks
So if you have not done an npm init then that is the issue. npm init initializes the project and will add the node_modules folder to the working directory, this will set it up as a node project. Then to install a dependency just run a npm install <dependency> although I do recommend doing a --save afterwards as well as it just ensures that the package is put in your current directory
$ npm init
$ npm install optionator --save
npm-init | npm Docs
Nothing worked until when I initialized the project in a new directory and reinstalled all the dependent modules afresh.
Need to give full access to package-lock.json
If you are using linux do this
sudo eslint init
I have a project on Github that ignores the node_modules folder, so I changed my computer and and cloned the repository again.
I used the npm-install-all install all node dependencies, it used to work.
But today when doing this and running react-scripts start I had this problem:
internal/modules/cjs/loader.js:888
throw err;
^
Error: Cannot find module 'which'
Require stack:
- C:\Users\jessica.marchi\Documents\GitHub\AUDIT-APP\node_modules\react-dev-utils\node_modules\cross-spawn\lib\util\resolveCommand.js
- C:\Users\jessica.marchi\Documents\GitHub\AUDIT-APP\node_modules\react-dev-utils\node_modules\cross-spawn\lib\parse.js
- C:\Users\jessica.marchi\Documents\GitHub\AUDIT-APP\node_modules\react-dev-utils\node_modules\cross-spawn\index.js
- C:\Users\jessica.marchi\Documents\GitHub\AUDIT-APP\node_modules\react-dev-utils\crossSpawn.js
- C:\Users\jessica.marchi\Documents\GitHub\AUDIT-APP\node_modules\react-scripts\bin\react-scripts.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
at Function.Module._load (internal/modules/cjs/loader.js:730:27)
at Module.require (internal/modules/cjs/loader.js:957:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Users\jessica.marchi\Documents\GitHub\AUDIT-APP\node_modules\react-dev-utils\node_modules\cross-spawn\lib\util\resolveCommand.js:4:13)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Module.require (internal/modules/cjs/loader.js:957:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\jessica.marchi\\Documents\\GitHub\\AUDIT-APP\\node_modules\\react-dev-utils\\node_modules\\cross-spawn\\lib\\util\\resolveCommand.js',
'C:\\Users\\jessica.marchi\\Documents\\GitHub\\AUDIT-APP\\node_modules\\react-dev-utils\\node_modules\\cross-spawn\\lib\\parse.js',
'C:\\Users\\jessica.marchi\\Documents\\GitHub\\AUDIT-APP\\node_modules\\react-dev-utils\\node_modules\\cross-spawn\\index.js',
'C:\\Users\\jessica.marchi\\Documents\\GitHub\\AUDIT-APP\\node_modules\\react-dev-utils\\crossSpawn.js',
'C:\\Users\\jessica.marchi\\Documents\\GitHub\\AUDIT-APP\\node_modules\\react-scripts\\bin\\react-scripts.js'
]
I already tried to update the modules with npm install.
Has anyone been through this and can you help me, please?
Thanks.
I finally got it!
If you have the same problem, try:
rm -rf node_modules
then remove your package-lock.json and
npm install
For me it was an xcode issue.
Remove xcode cli tools: sudo rm -r -f /Library/Developer/CommandLineTools
Reinstall: xcode-select --install
Then, delete node modules. Manually or with rm -rf node_modules
Should be good to go: npm install then npm start
https://github.com/haileemiu/Notes/blob/main/Troubleshooting/npm.md
this problem occur in node version-17 just download version-16 and it works
I'm using Backpack to build my node app. When running the app locally, the app itself and the build artefacts are doing okay. But when I move the build results to a Docker image and try to run it, I get the following errors:
Error: Cannot find module 'source-map-support/register'
Require stack:
- /home/app/main.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
at Function.Module._load (internal/modules/cjs/loader.js:667:27)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/app/main.js:1:1)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/home/app/main.js' ]
My Dockerfile:
FROM node:12.21-alpine
ENV NODE_ENV=production
RUN mkdir -p /home/app
COPY ./build /home/app
WORKDIR /home
CMD ["node", "./app/main.js"]
What am I missing? Are there other alternatives for Backpack? Basically, I want to build my app first, move the artefacts into a Docker image and then run that. I'm not looking to build inside an image.
You are missing node_modules.
You have to copy node_modules to container COPY ./node_modules /home/app/node_modules
Or install it during the docker build (remember to copy package.json and package-lock.json) RUN npm ci.
If it is a local development env, you can choose the first option. But if not, a better way is second one.
For some reason my npm start doesn't work anymore, cause: this occurred right after switching to some unused branch (with unrelated histories) and pushing any changes (not realizing that this branch was some outdated one), then git checkout -f "" back to the recent branch. Now it doesnt work for any of my branches due to error Error: Cannot find module 'serialize-javascript'
Full error here:
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'serialize-javascript'
Require stack:
- /home/abdullah/ecommerce-recommend-frontend/node_modules/rollup-plugin-terser/index.js
- /home/abdullah/ecommerce-recommend-frontend/node_modules/workbox-build/build/lib/bundle.js
- /home/abdullah/ecommerce-recommend-frontend/node_modules/workbox-webpack-plugin/build/generate-sw.js
- /home/abdullah/ecommerce-recommend-frontend/node_modules/workbox-webpack-plugin/build/index.js
- /home/abdullah/ecommerce-recommend-frontend/node_modules/react-scripts/config/webpack.config.js
- /home/abdullah/ecommerce-recommend-frontend/node_modules/react-scripts/scripts/start.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> (/home/abdullah/ecommerce-recommend-frontend/node_modules/rollup-plugin-terser/index.js:3:19)
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: [
'/home/abdullah/ecommerce-recommend-frontend/node_modules/rollup-plugin-terser/index.js',
'/home/abdullah/ecommerce-recommend-frontend/node_modules/workbox-build/build/lib/bundle.js',
'/home/abdullah/ecommerce-recommend-frontend/node_modules/workbox-webpack-plugin/build/generate-sw.js',
'/home/abdullah/ecommerce-recommend-frontend/node_modules/workbox-webpack-plugin/build/index.js',
'/home/abdullah/ecommerce-recommend-frontend/node_modules/react-scripts/config/webpack.config.js',
'/home/abdullah/ecommerce-recommend-frontend/node_modules/react-scripts/scripts/start.js'
]
}
The node_modules/serialize_javascript does exist and has a settings.json file in it:
{
"spellright.language": [
"en"
],
"spellright.documentTypes": [
"markdown",
"latex",
"plaintext",
"javascript"
]
}
I have tried running npm install (with -g as well, and in the node_modules/serialize_javascript dir) with output:
up to date, audited 1725 packages in 2s
130 packages are looking for funding
run `npm fund` for details
1 critical severity vulnerability
Some issues need review, and may require choosing
a different dependency.
Run `npm audit` for details.
And npm audit:
# npm audit report
node-serialize *
Severity: critical
Code Execution through IIFE - https://npmjs.com/advisories/311
No fix available
node_modules/node-serialize
1 critical severity vulnerability
Some issues need review, and may require choosing
a different dependency.
What's weird is that even checking node -version (node -v works now after sudo get-apt update) gives a similar MODULE_NOT_FOUND error:
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module '/home/abdullah/ecommerce-recommend-frontend/–v'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Note: This only occurred after uninstalling node, then reinstalling in wsl with sudo:
rm -rf /usr/local/lib/node_modules/npm
sudo apt-get remove npm
sudo apt install nodejs
sudo apt-get update
Any ideas? Might try to just get rid of node from windows even though I use WSL and then reinstalling everything
Nevermind, I just copied an old serialize_javascript module from a previous commit since it had more stuff than just the settings.json and ran npm install to get it working.