Error while using create-react-app - ENOENT - node.js

New Node & React user here. I'm following the React tutorial but run into a problem on my Windows 10 machine:
C:\Users\Wout>create-react-app my-app
Creating a new React app in C:\Users\Wout\my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
npm ERR! path C:\Users\Wout\my-app\node_modules\abab
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\Wout\my-app\node_modules\abab' -> 'C:\Users\Wout\my-app\node_modules\.abab.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Wout\AppData\Roaming\npm-cache\_logs\2018-03-14T15_21_11_867Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... node_modules
Deleting generated file... package.json
Deleting my-app / from C:\Users\Wout
Done.
Things I've tried so far:
Reinstall Node.js (v8.10.0, npm 5.6.0)
Disabling Adobe creative cloud sync & related processes (these were spawning node.exe processes)
Running CMD in admin
Run the command from VS Code Powershell
Closing Visual Studio Code before executing the command
Run the command with npx
Rebooted the system several times
Running the command from the user folder as well as other drives
Running the Typescript version: create-react-app my-app --scripts-version=react-scripts-ts
It's all quite strange to me, since on Mac OS X the command executes without issues. I also can't seem to find other people with the same problem.
For what it's worth, it always stops after this "finalizing abab" package step.
I have an installation of XAMPP running an Apache and MySQL service, don't know if that has anything to do with it. I don't think so since I'm not even running the app yet, plus the server runs on port 3000 anyway.

I eventually solved it by closing as many extra processes as possible. Will try to find out which process was interfering with the command.
Edit: Ding ding ding! It was MalwareBytes! The "realtime protection 30-day trial" had restarted after an update and it was screwing with the filesystem.

I also just installed MalWareBytes, and I get the same error. I tried running create-react-app from the CLI as administrator, and while it was running I read your solution, and so I shut down MalWareBytes as the installation was in progress.
It worked, but I don't know if that is because I ran as administrator, or because I shut down MalWareBytes.
But for anyone having this problem, you could also try running your command prompt/powershell with administrator rights.

try running the command from the project directory...
worked for me.
i ran the command from the parent of the project directory for example:
reactApp/hellowworld
run from helloworle directory instead...

In case you have just install the create-react-app command , try to run the command from a new terminal . (re-open another tab).

Related

Why is npm showing ERR! code EPERM when trying to install eslint dependencies in my local project folder?

The error stack shown in the git bash terminal of Vscode (image is a link because I am new to stack overflow with low reputation)
I've been trying to configure eslint for a local project and so far npm i -D eslint has worked. However ./node_modules/.bin/eslint --init brings me to installing the dependencies and that's where it causes problems. It seems there are some permission issues and it's giving npm ERR! code EPERM.
Things I've tried:
Restarting machine
Using windows terminal as administrator
Closing/reopening VScode
Using git bash outside of VScode terminal
What can I do to allow permission for the operation?
The error messages make it clear that it is likely not an error from NPM itself but rather the files and their accessibility.

npx react-native init AwesomeProject error enolocal

i got an error while trying to create react native app using npx npx
react-native init AwesomeProject
like the docs said. But i got an error messages
npm ERR! code ENOLOCAL npm ERR! Could not install from
"Indigo\AppData\Roaming\npm-cache_npx\3192" as it does not contain a
package.json file.
npm ERR! A complete log of this run can be found in:
C:\Users\Durio
Indigo\AppData\Roaming\npm-cache_logs\2020-07-08T08_20_54_191Z-debug.log
Install for react-native#latest failed with code 1
i know it's not from the npx because i tried to create react app with npx and it works. Am I the only one who had this?
This is an issue in node which is caused by white space in user name between first-name and last-name in windows.
run the following command after replacing firstname with your windows user firstname in command prompt with administrator access
npm config set cache "C:\Users\Firstname~1\AppData\Roaming\npm-cache" --global
I had you try npm cache clear and if using windows you can run command npx react-native init AwesomeProject in Command promt using Run as Administrator
I have faced the same issue, do nothing just a quick fix.
first, run the command npm i react-native#latest -g then create your project with your command i.e npx react-native init myProject
we should check the android SDK path on environment variable. Make sure there is no white space on the SDK path and platform-tools path

npm and other modules commands not working

Note: I am on Windows 10 64 bit running the latest LTS Node build.
It all started when I tried running the command npm i -g create-react-app and I get a message saying that npm is not a command.
I checked my PATH and I believe I have the proper directories in there.
I navigated to the directory of npm and tried running the command again, but it still didn't work. I found that the command npm.cmd worked in any directory. So tried running npm.cmd i -g create-react-app and that worked! I also had to use the the command create-react-app.cmd my-app, instead of create-react-app my-app. I thought I was set and I could just use those .cmd commands for the things I needed to do; however, when I tried to run the command create-react-app.cmd my-app and got this as a result:
I have looked in the file that is ran when using this command create-react-app.cmd my-app and there is no sign of npm being called. Turns out Node is being called in that file with the command below. I know this because when I run it by itself and I get the same output to the console seen in the previous image.
"node" "C:\Users\Allen\AppData\Roaming\npm\\node_modules\create-react-app\index.js" my-app
it was called in the create-react-app.cmd file like this "%_prog%" "%dp0%\node_modules\create-react-app\index.js" %*
I am at a loss. I could continue down this rabbit hole and try and find the node file that is calling npm and change it to npm.cmd but I would rather find a way to get the npm and create-react-app commands working as they are suppose to. At the very least I can just spin up a VM and work in that. It is just annoying that I can't get Node to work properly for me.
Use the command npx create-react-app my-app this will help you create react projects.
Also check the documentation : https://reactjs.org/
First check that you have npm installed on your machine and the version. You can just type npm version. Since npm version 5.2.0 npx is pre-bundled with npm, which is a CLI tool whose purpose is to make it easy to install and manage dependencies hosted in the npm registry. So try using npx create-react-app app-name. You can confirm that you are able to use npx by running which npx. If it is not available then you can install it by running npm install -g npx.

sh: 1: node: Permission denied

Tried to run this command on ubuntu 18.04
npm install -g pngquant-bin
but I got this error,
[..................] | fetchMetadata: sill resolveWithNewModule npm-conf#1.1.3 checking installable status
npm WARN deprecated gulp-util#3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
/root/.nvm/versions/node/v10.8.0/bin/pngquant -> /root/.nvm/versions/node/v10.8.0/lib/node_modules/pngquant-bin/cli.js
> pngquant-bin#5.0.0 postinstall /root/.nvm/versions/node/v10.8.0/lib/node_modules/pngquant-bin
> node lib/install.js
sh: 1: node: Permission denied
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! pngquant-bin#5.0.0 postinstall: `node lib/install.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the pngquant-bin#5.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-08-12T18_08_02_197Z-debug.log
Do you do you know how to deal with this?
I tried every solution found in this articles yet not succeeded.
Got the same error sh: 1: node: Permission denied
So this worked for me
npm config set user 0
npm config set unsafe-perm true
These issues happen because of broken packages. Go to the main folder. If using Linux use command
sudo rm -rf node_modules.
After that run this command if you are using yarn
yarn install
If you are using npm run this command
npm install
Delete the node_modules and install it again
sudo rm -rf node_modules
npm install
in fact, npm can't use root account to install anything. if you use root account, npm will create a non-permission account to install. in this case, if the package need to execute writeFile or other operation which need permission, the error node: Permission denied will be raised.
so, you can choose optional arbitrary under:
npm install xxx --unsafe-perm
npm config set unsafe-perm true
create high-permission account dedicate to execute npm install
In my case it was a silly typo, I was forgotten to add node into the front of the start command in package.json. So I've changed:
"scripts": {
"start": "app/server.js"
}
... to:
"scripts": {
"start": "node app/server.js"
}
The /root/.npm/... log path in your original message shows you're already running as root, and (despite what others advise) I'd say this is most likely causing your problem.
My (limited) experience running Node as root is that most npm install runs get quite a long way, but then fail with some variation on the error you showed. The only reliable solution I've found is to not run Node or npm as root at all on Ubuntu. Just use a normal user account to download and unpack the Node installation.
At least one problem with running as root for me turned out to be because some dependency-of-a-dependency npm install script was calling setuid to switch to a less-privileged user. For some reason, it chose UID 500—which doesn't exist on Ubuntu—and consequently lost all its privileges. The 'Permission denied' errors were therefore because I was running as root; setuid doesn't work for a normal user.
I believe this is related to Error: setuid user id does not exist npm ERR! when npm install forever -g.
Solved my problem chmod -R a+x node_modules
As far as my understanding goes the os is blocking your ability to execute commands described in node_modules so by my understanding what this command does is say everything in node_modules is okay to execute.
By the time I found the solution it was 4 AM, so I didn't really bother to figure out what I actually did. If someone knows what -R a+x node_modules does exactly feel free to drop it in the commands and I will make an edit.
I make the chown to project user owner (in USERID) dir and resolv the "permission denied" problem:
sudo chown -R USERID.USERID *
Additionally (and this might be useful for docker) you can override this configuration setting globally via the environment variable npm_config_user -- for example:
ENV npm_config_user=root
I ran into the same error an nothing really helped. I found a medium article explaining how to set up an angular build management. For some reason adding
- npm link #angular/cli#13.2.5
to my build script made it. I basically added all of the recommendations above. So my build script now looks like this
- ...
- npm config set user 0
- npm config set unsafe-perm true
- npm i --force
- npm link #angular/cli#13.2.5
- ...
I hope it helps! I would be happy if someone could explain why it actually worked.
This is an old question but maybe someone still need some help.
This errors often is displayed because you have defined in the package.json just the path. For example:
{
// more definitions
"scripts": {
// other scripts
"getPax8Products": "<filepath>",
// more scripts
},
// more definitions
}
In this case, you need to:
Add the following lines in the very beggining of the script
#!/usr/bin/env node
'use strict';
Give the file execution permission
# in UNIX based
chmod +x <filepath>
You also can modify the package.json and add the node command. However, you need to be aware that NPM will run in the script's directory:
{
// more definitions
"scripts": {
// other scripts
"getPax8Products": "node <filepath>",
// more scripts
},
// more definitions
}
For Deploying with Docker:
make sure /node_modules is deleted or added to dockerignorefile
make sure /dist is deleted or added to dockerignorefile
the problem was solved for me by deleting both files
and build them in the container
For me, I had not installed my dependencies. node_modules did not exist, but I had jest installed globally apparently. Running npm ci and then running npm test solved my issue.
npm install lite-server --save-dev
packages.json:
"scripts": {
"dev": "lite-server",
},
"devDependencies": {
"lite-server": "^2.6.1"
}
npm run dev
I stuck with same issue when tried to install packages into AWS Sagemaker instance
The issue coming because NPM by default install new global packages into ~/.npm-global
When you run npm install -g by root, npm is try to install package into /root/.npm-global/..., and stuck with access denied.
Simply workaround to re-config global folder for npm.
(https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally)
Here is example of install obj2gltf
mkdir /npm-global
npm config set prefix '/npm-global'
export PATH=/npm-global/bin:$PATH
npm install -g obj2gltf
I had that error too and tried the above solutions without any change. My error was caused because I had Windows (11) with a WSL and NVM installed on both operating systems. I had to uninstall NVM on my Windows to resolve the conflicts.
I think if you develop in your WSL and have a resource installed on both operating systems, a dependency might point to the wrong operating system with the resource (in my case to the NVM on Windows). The WSL user didn't have sufficient permissions to perform any execution on the Windows machine, which lead to the error.
you need root user permission, just add sudo keyword before the command and write your password
sudo npm install -g pngquant-bin
Try to install node at project folder
npm install node

npm always using home directory as current working directory

npm insists on using my home directory as the current working directory, no matter which directory I am executing commands from.
Happens with both cmd and Powershell, I've tried removing and reinstalling node, both using the installer on nodejs.org, and via Chocolatey with the same result.
If I navigate to e.g. C:\test and run npm init, the wizard places the resulting package.json file in my home folder.
If I run npm install <package> from any folder, the package is installed to C:\Users\myusername\node_modules
Trying to install a package globally also fails, with this
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\ProgramData\\chocolatey\\lib\\nodejs.commandline.0.10.33\\tools\\node.exe" "C:\\ProgramData\\chocolatey\\lib\\npm.1.4.9\\tools\\node_modules\\npm\\bin\\npm-cli.js" "install" "gulp" "-g"
npm ERR! cwd C:\Users\<myusername>
If I navigate to a folder, start the node REPL and run process.cwd() the directory I started node from is returned, so the issue seems to be limited to npm.
Running npm get gives this result:
C:\test> npm get
; cli configs
registry = "https://registry.npmjs.org/"
user-agent = "npm/1.4.9 node/v0.10.33 win32 x64"
; node bin location = C:\ProgramData\chocolatey\lib\nodejs.commandline.0.10.33\tools\node.exe
; cwd = C:\Users\<myusername>
; HOME = C:\Users\<myusername>
; 'npm config ls -l' to show all defaults.
I've searched quite a bit for a solution, and have found some similar issues, but none that solved my problem. I know that npm walks up the directory tree to look for a node_modules folder, but this happens in folders outside my home directory as well.
Any tips on what I try to resolve this?
Turns out I had a cd C:\Users\<myusername> command in HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun in the registry. Meaning that this command was executed any time CMD.EXE started.
No idea how that got in there, I might have added it myself at some point.
Anyway, if someone experiences differences between the current working directory when executing a script and when running the same command manually in an open command prompt, HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun and HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRunare good places to check.
Not 100% sure but I think you'll get this if when you don't have a package.json file. Try to create one (npm init) then try installing any modules. Should then save them under node_modules of whatever current directory you're in.

Resources