Can't install ExpressJS - npm is throwing an error - node.js

When I try to install ExpressJS with the command npm install -g express, I get the following errors:
What can I do about it?

I assume node -v gives 0.10.something.
Get rid of it and install a newer version of node from nodejs.org. Also try removing node_modules and npm install everything again.

Actually, I fixed the problem by uninstalling the latest version and installing the currently recommended one for most users - version 6.9.1.
The cause of the problem still remains unknown.

Related

Error npm is known not to run on Node.js v10.24.1 and how to fix it, don't update to the latest version?

I run : npm run dev
Error : npm is known not to run on Node.js v10.24.1
I have researched and know the command: npm install -g npm#latest and some other commands to fix the problem
But the problem is that my project is using nodejs 10 so it can't use the latest nodejs. So is there any way to fix the above error. Thank you
UPDATE :
I use nvm to install and manage versions of nodejs. And my OS is macOs
The problem for me was upgrading my global version of npm while on an incompatible version of Node (8.16.1).
I tried to uninstall npm globally but that also didn't work because I could not use the npm command.
To fix it, I used nvm to switch to a compatible version of Node (nvm use 14.0.0 - this can be any version of Node compatible with the npm version you have installed globally). This allowed me to run npm commands so I ran npm uninstall -g npm first of all to remove my global version of npm and then nvm uninstall 8.16.1 to remove my faulty Node version.
I was then able to reinstall Node 8.16.1 (nvm install 8.16.1), and with it came a fresh install of a compatible npm version.
I happen to work on a project that builds on node 10 as well.
More details would have been helpful to understand the problem better but I suspect it's a compatibility issue.
Try these:
Download and install the latest version of nodejs.
Open you terminal and verify you have the latest version using node -v. Verify your npm version too using npm -v.
Since you have nvm installed, run nvm install 10, then nvm use 10.
Verify your versions again. In my case, node is v10.24.1 & npm is 6.14.12.
Start your app using npm run dev. Please check you package.json to be sure you are using the right startup command.
I was having the same problem, I ran the command and it solved the problem with NPM
sudo n latest
Node: v10.19.0
NPM: 8.9.0
Reference
I performed an upgrade of npm by mistake and run into the same issue.
The only way to solve for me was to delete the two following directories:
C:\Users\<username>\AppData\Roaming\npm
C:\Users\<username>\AppData\Roaming\npm-cache
npm is known not to run on Node.js v10.24.1 comes when normally people upgrade the version of npm to latest or recent ones, but when it comes to node 10 version you can use npm version 6.4.1 or 6 series. Normally npm 6.4.1 will come with node js 10.24.1 but if you have given any npm update cmd you need to go to C:\Users\username\AppData\Roaming and delete npm and npm cache folders then delete npm folders in C:\Users\username\AppData\local then check the npm version using npm -v. After doing this install the angular version
Thanks #Oduola Olumide Sunday for the response. I have followed your way but still not solved the problem.
And I fix it by removing the latest nodejs version and using the normal node v10.24.1
enter link description here ->
I removed the latest nodejs version with this
This error happens when your npm version is not what you think it is...
For instance, you download a nodejs pkg and install. Run node -v, npm -v... npm -v provides the error that brought you here.
This means your aren't using the version the nodejs pkg installed, but some remnant somewhere- from other install attempts.
In my case, I had a Homebrew installed version of npm that I didn't realize existed.
You can find the locations, at least on mac, using the 'where' command.
where npm
Which will return path(s) of your npm locations. Find the one that doesn't belong and give it the boot.
Then your npm -v will return the expected version number output.
Now you can execute npm commands.
I had the same problem.
I was using node 12 with nvm
Then, I switched to node 16, uninstalled the version 12 with nvm uninstall 12 and then I installed it again with nvm install 12 and it is working fine
For nvm used under macOS, I solve this issue in this way
First, run nvm ls-remote to get the latest version of v10
-> v10.24.1 (Latest LTS: Dubnium)
Then install the latest version of v10 through
nvm install 10.24.1 --latest-npm
In case anyone here needs to install an npm version (7.24.2) that does support node 10, rather than upgrade node.
Here is what I did:
url=`(curl -qSsL https://registry.npmjs.org/npm/7.24.2; echo "") | sed -e 's/^.*tarball":"//' | sed -e 's/".*$//'`
curl -qSsL -o npm.tgz "$url"
bin/npm-cli.js install -gf ../npm.tgz # in case npm is not installed where "which npm" points to, you might need to add --prefix=$(which npm | sed 's/\/bin\/npm//')
The reference is the installation script of 7.24.2 https://github.com/npm/cli/blob/v7.24.2/scripts/install.sh
In my case I had put ^ in one of the package version in my package.json. Which takes latest version of that library and it was not compatible to older npm version which caused me this error.
Remove all ^ from package versions and try again.
your nodejs version should come with its own npm that it supports.so if your machine has issues finding the npm version go to cdrive C:\Users\Machine name\AppData\Roaming
delete npm and npm cache folders.
Try below command
brew install node
then
npm install
None of the tips I found here helped.
I had to reinstall nvm.

Strapi V4 Error: Can't resolve '#strapi/design-system/themes'

I'm trying to run the new Strapi version 4 application. But it returns this error.
Is there any bug in new strapi v4? or I'm doing wrong anything?
I'm using strapi official guide to start a new project
installation command npx create-strapi-app#latest molla-admin.
NodeJS v16
Windows 11
Error
ModuleNotFoundError: Module not found: Error: Can't resolve '#strapi/design-system/themes' in 'C:\Users\Admin\Desktop\molla-admin\.cache\admin\src'
at C:\Users\Admin\Desktop\molla-<anonymous>:10:1)
You might be thinking #strapi/design-system package is missing right? After that, I also tried to install both #strapi/design-system and #strapi/design-system/themes npm package
Still, it doesn't work. It returns a new error
ModuleNotFoundError: Module not found: Error: Can't resolve '#strapi/icons/CarretDown' in 'C:\Users\Admin\Documents\testing\strapi-v4-app\node_modules\#strapi\helper-plugin\build'
Should I go on for the next missing Module?
For me the issue was solved by installing #strapi/design-system (Node: v14.15.5, npm: 8.1.3)
npm install #strapi/design-system
Node version : 14.18.1
Npm version : 6.14.15
OS : Ubuntu 20.04.3 LTS
Steps I followed:
(I read somewhere that the latest version of node isnt working and
someone mentioned using the 14.18.1 version)
Downgraded NPM to use the 14.18.1 version and not the latest.
npm run build on the strapi project. This gave an error that its
missing #strapi/design-system.
npm install #strapi/design-system, you get another error that its missing #strapi/icons
npm install #strapi/icons . After this step there was an error relating to JSX scritps something to do with reactjs. So, in the next step , I updated Reactjs
npm install --save react#latest
npm run build again and this time SUCCESS!!
The strapi team should mention the issues on their homepage rather that making new users go through hoops to get it working. They need to make it clear that you can run into issues when using certain version of Node etc. As someone mentioned that they are aware of the issue yet no information in the homepage where new users visit to try it out. It should've been placed as a BANNER at the top in BOLD TEXT.
It's a known bug and they are working on a fix.
You have to use yarn in the mean time.
I can confirm that this bug is related to using Node v16. To get around the bug, I first ran:
nvm use 14.18.1
Afterwards, running the following resulted in successful compilation:
npm run build -- --clean
No need to attempt installation of #strapi/design-system.
I got this error because I was using Node v16. There was a message somewhere in my troubleshooting that you have to use A Node version >=10.X.X.X and <=14.X.X.X
I used NVM(Node Version Manager) to switch to 14.17.6 and it works
following solution worked for me:
yarn add #strapi/design-system
yarn add #strapi/icons
work on windows and ubuntu
node v14.15.0
yarn 1.22.17
npm 6.14.8
npm install #strapi/design-system
solution worked for me.
node 16.13.1
npm 8.1.4
macOS 12.0.1 on M1Max

Cannot find module 'fs/promises' Electron JS

Good morning,
I have created a program in Vue JS, this connects with an API that I have created in a main.js file to execute system commands.
The problem I have is that when compiling for production with electron I get the following error:
I use the command npm run electron: build
When I use npm run electron:serve work without problems
Anyone have any idea why is the error and how to fix it?
Thanks
I experienced this issue a few days ago as well. I realized that trying to fix another issue, I deleted the node_modules folder and the package-lock.json file, then run the npm install command. This made the build to fail with 'fs/promises'. There are 2 solutions to this issue:
Download the latest stable Node version. This should have the 'fs/promises' module and will fix the issue.
Delete the node_modules folder and bring back the old package-lock.json file to ensure that the package versions remain the same. Then run the npm install command and the issue should be fixed.
downgrade electron
"electron-builder": "^22.10.5",
or upgrade nodejs to 14+ v
downgrade to "electron-builder": "~22.10.5" is working for me
In that case I fixed the problem in that way:
const fs = require('fs').promises;
Instead of:
const fs = require('fs/promises');
In my case I was using nvm to manage multiple node versions.
During the npm package installation, and throughout development, I used Node v14 but for some reason, my terminal was pointing to Node v12 when I tried bundling my program afterwards.
Switching it back to Node v14 using nvm use 14 solved my issue.
So make sure you're using the correct node version.
Upgrade to electron-updater#5.0.0. It has patch changes replacing fs/promises with fs-extra to support legacy versions of electron.
got the same error "Cannot find module 'fs/promises'" while I don't use electron.
so the problem is not only related to electron
solved the problem just by upgrading nodejs from v13.9.0 to v14.19.3
If this happens to you (and I'm not using Electron either), and you have to stay on Node 12 like me (because the code you are maintaining is ancient), pray that you can get to one of the npm-shrinkwrap.json files you used that worked, then go through package.json, force every version to what was in the shrinkwrap file, rm -rf node_modules, and npm install.
I experienced this issue a few days ago. I realized that trying to fix another issue, I deleted the node_modules folder and the package-lock.json file, then run the
npm install
This made the build to fail with 'fs/promises'.
Delete the node_modules folder and bring back the old package-lock.json file to ensure that the package versions remain the same
then run the npm command with force
npm install --force
it work for me..
I had the same problem, after upgrading the electron-builder from v. 21.4.0 to 23.0.2, updated with the command:
 
sudo npm install -g electron-builder#23.0.2
I solved updating npm, and then node.js.
Update npm:
sudo npm install -g npm#latest
 
Install nodejs from https://nodejs.org
Now it works with :
 
Electron-builder: 23.0.2 (command electron-builder --version)
Npm: 8.7.0 (command npm --version)
Nodejs: v16.15.0 (command node --version)

npm ERR! cb.apply is not a function

I am getting this error
npm ERR! cb.apply is not a function
in Linux while doing npm install although my npm version is 6.9.0. My node version is v12.18.3. How to resolve this issue?
Would be helpful if you shared if it's Windows or Linux, but the error seems to occur on Windows. Possible solution:
1. Go to C:\Users(your username)\AppData\Roaming
2. Delete the npm folder (possibly back it up) and if there is one npm cache folder.
3. Run `npm cache clear --force` (--force is now required to clean cache)
After that, npm install should work fine.
Mac/Macbook users
Since this question is fairly active and a top google result for this issue (I know the OP is using Linux), here is how to fix it on a Mac.
On a Mac you do not have the AppData\Roaming folder, so simply run npm root -g and then navigate to the hidden directory and delete the node_modules there. If using nvm you'll need to rerun nvm use x.x.x (where x.x.x is your version).
Solution for Windows:
In my case I didn't want to delete all the npm directory inside C:/users/me/AppData/Roaming/ because I had many global modules that already existed and installed.
What worked was inspired by #user14360499's answer:
go inside C:\Users\me\AppData\Roaming\npm\node_modules
delete the npm dir
npm install my project, and keep working as usually
Solution for ubuntu 18.04:
sudo apt-get remove nodejs
sudo apt-get remove npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/bin/npm
sudo apt-get install nodejs
sudo apt-get install npm
Then try node and npm version:
node -v
npm -v
If it says there is no such node/npm after you already install, then:
sudo ln -s /usr/bin/node /usr/local/bin/node
sudo ln -s /usr/bin/npm /usr/local/bin/npm
Try this if the command works:
npm -v
node -v
In case when you want to update npm/node stable version:
sudo npm install n -g
sudo n stable
I had the same issue with Nodist. After changing my Node version, my npm version was actually incompatible with it. So if you're using Nodist, make sure to run nodist npm {scope} match after switching Node versions, where scope is either global, local or env.
For me, on Centos 7, it was about removing graceful-ts used locally by npx. First, I've had to open log file which was mentioned in the error message:
npm ERR! cb.apply is not a function
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-04-04T07_45_27_182Z-debug.log
In that log file there was this path:
verbose stack at /usr/local/lib/node_modules/npx/node_modules/npm/node_modules/graceful-fs/polyfills.js:287:18
So I removed whole graceful-fs directory and ran npx again. Everything worked.
rm -fR /usr/local/lib/node_modules/npx/node_modules/npm/node_modules/graceful-fs
Had the same error (macOS Big Sur) when i tried to use npx.
How i fixed it (using nvm)
when i run:
nvm ls
nvm ls output
Fix:
nvm alias default node
nvm install 'lts/*'
nvm install output
Ciao, this problem could be connected to graceful-fs package. You could try to reinstall it:
npm install graceful-fs --save-dev
In my case it was indeed the graceful-fs package. Running
npm i -g --force graceful-fs
fixed the issue. I also ran nodist npm {scope} match before but I'm unsure if it was neccessary.
Solution for Ubuntu 18.04=>
Visit 'usr/lib/node_modules'.
Delete 'n', 'npm','npm-clean','npm-install-peers'. That means delete all the node & npm related folders.
Install the npm again.
I have tried a lot of solutions from different posts and google pages and nothing worked for me.
I ended up cleaning all traces of node, nodejs, and npm. May need some manual force remove after the purge call. And then installed using nvm.
https://linuxize.com/post/how-to-install-node-js-on-ubuntu-20-04/#installing-nodejs-and-npm-using-nvm
And it resolved the issue for me. It got the nodejs v 15.4.0 and the compatible version of npm 7.0.15 ( before using apt-get it was installing npm 6.9.0)
On macOS BigSur, I had this problem when executing:
npx install-peerdeps --dev eslint-config-airbnb
To fix, I ran
brew update
after which I was prompted to run
brew upgrade
Running the two commands fixed the issue.
I had this problem while trying to run npx.
I found that nvm had been removed from the PATH.
I added it back to my .zshrc file and it worked.
In my case (Mac) it was because I had npx installed alongside n (alternative to nvm).
$ which npx
/usr/local/bin/npx
I removed this exectutable and now:
$ which npx
/Users/MY_USER/n/bin/npx
and it works now.
I was getting this error when running npx sb init. For some reason, the command worked localy but not in CI. I tried most of the solutions from here. But only the following worked.
I replaced npx sb init with yarn global add #storybook/cli && yarn exec sb init as suggested here: https://github.com/yarnpkg/yarn/issues/3937#issuecomment-751289438
(NVM, Node.js 14, Yarn 1)
if you are also getting this error:
1 warn npm npm does not support Node.js v16.2.0
that means that your npm version is not correct.
reinstall npm, try again.
It works for me.
Feb 2021 fix:
npm install
And then commit the changes to package-lock.json. That should update all your dependencies, thus fixing this issue.
More info: https://help.heroku.com/ZV7S7D6T/why-is-my-node-build-is-suddenly-displaying-npm-err-cb-apply-is-not-a-function (this happened to me on heroku)
For linux users:
uninstall NPM, to do it go to /usr/local/lib/node_modules and do:
sudo rm -r n npm npx
Once uninstalled, re-instal it:
npm install
Even after doing this, in a specific project when trying to install a specific npm package, you may get the following error:
bash: /usr/local/bin/npm: No such file or directory
If so, in the terminal just run:
hash -r
Now you can retry installation of your wanted npm package.
For me , the solution was to delete the node modules and bower components folder of the project.
for the mac OS remove the node version and reinstalling was work for me. I used n npm version manager.
On windows, using nvm, i just installed a newer nodejs version (before 14.17.0, now 14.18.2)
So many solutions just made me even more puzzled. I downloaded and installed the newest LTS NodeJS and it worked just fine.
https://nodejs.org/en/
I'm on a Mac, and had exactly the same issue. Deleting the node modules seemed a little overkill for me, so I ran npm update and it solved the issue! Please note I did not yet have any package.json or any modules on the repo I was working in.
Windows 10:
When calling npx create-react-app my-app, i got following error:
npm ERR! cb.apply is not a function
To fix it, i did the following:
Go to the folder you want to create the app in.
npm install create-react-app --save-dev
npx create-react-app my-app
The problem has occured when the node and npm packages are not latest.
For me the problem is resolved when I completely removed npm and node, and made a clean installation.
I am using ubuntu 22 lts
to remove node and npm completely I have followed this answer
Had this issue when creating a new react app using create-react-app.
I was using nvm, so I just updated it to the latest LTS version:
nvm install --lts
then switched to the newly installed lts version:
nvm use --lts
closed and reopened the terminal, reran create-react-app and the error was fixed!
Solution for ubuntu =>
Completely remove nodejs and npm from your system.
sudo apt-get remove nodejs
sudo apt-get remove npm
Install node from this reference (https://computingforgeeks.com/install-node-js-14-on-ubuntu-debian-linux/) - This will inturn install latest npm .
Had the same error was simply in the wrong folder -.- (not a typescript project)

Unexpected end of JSON input error when creating new project

Each time I use angular/cli to create a new project by launching the following command
ng new Project-Name
I get the following error
npm ERR! Unexpected end of JSON input while parsing near '...-4","#angular/common"'
I tried to force clean the cache and re-try but still face the same problem.
NodeJS version: 12.16.3
npm version: 6.14.4
Angular CLI version: 9.1.4
OS: Windows 10 Home win32 x64
Edit: All the commands above I run them in Powershell as administrator
This is not a definitive answer but it looks like your global packages are corrupted in some way.
This bug may be caused by many different things. I suggest doing the following.
Install Node Version Manager (or NVM for Windows) and install Node version 10.16.1. This is enough for angular 9 and from my experience it is the most stable version for development. This should also change your NPM version so that may also help.
Uninstall global angular package npm uninstall -g #angular/cli
Force clear cache npm cache clean --force
Just to double check npm cache verify
You can also try clearing your %temp% and %roaming% AppData/npm-cache
install latest angular package npm install -g #angular/cli#<your-version>
if this error still occurs, consider using another shell
If this don't solve the problem try to manually locate the package.json file that is throwing an error and investigate.

Resources