On start new react project I have this problem - javascript

When I run npm start, I get this error. What is the solution for this?

This issue has been addressed here, you can refer to it.
Complete solution is
First add Poweshell to PATH as %SystemRoot%/system32/WindowsPowerShell/v1.0.
open powershell as admin and write this command Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force.
last thing fire npm-windows-upgrade.

Check your node version. update node & npm
try sudo npm start if you are in macOS or linux
try to download create-react-app again npm i -g create-react-app
try to create the app in another folder create-react-app APPNAME
Still not working? Then delete node module folder and run npm install
Not yet? delete both node module & package-lock.json and npm install
Try to run on another PORT

Related

npm start is not working in cmd and it is showing error as shown in image?

This image contains details about the error when I am typing npm-start
I have created a react-app using create-react-app. I have created another app using the same but when I type npm-start, it displays an error and localhost:3000 stops working.
Missing npm package
Use the cmd to install npm package npm install
Check the docs here
To solve this problem you can follow these steps.
First, reinstall node_modules:
rm -rf node_modules/ && npm i //(rm -rf will only work if you have macOS for windows you need to delete node_modules manually)//
Then, start the project:
npm start
or
yarn start
This error solved by few easier simple steps. That steps are
Go to your setting
Open your environment variable screen
Delete ComSpec variable completely and click ok
Uninstall your NodeJS
Reinstall your nodejs setup,
Finally it will be work

"npm-run-all" Is Not Recognized As an Internal or External Command

I installed npm-run-all and also configured the environment variable (which may or may not be not required) on my Windows machine but am getting an error:
'npm-run-all' is not recognized as an internal or external command,
operable program or batch file
I am trying to build my current project with npm run build which includes the script where the error is thrown:
npm-run-all -p build-css build-webpack
Do I have to do any additional things to make it run?
Make sure the npm-run-all is in your package.json devDependencies.
If npm-run-all is present in your package.json, run npm i
If not present install it, run: npm i npm-run-all -D
If error is still present, follow these steps:
Remove node_modules folder: run rm -rf node_modules
Install all dependecies: run npm i
Hope this helps!
You may just need to run the following command first (from the directory with the package.json file)
npm install
Please do that like this.
npm i npm-run-all -g
And then this issue will be fixed.
You have a couple of options here, besides installing npm-run-all as a global package as suggested by #Vaibhav in the comments:
1) Create an NPM script
The package.json file has a scripts section which can used to define shortcuts for anything you need to run while you're working on your app. There are some pre-defined scripts, like run or test than can be executed with simply npm start/npm test or you can define anything you like and then run it with npm run my-script-name. You could try:
{
"scripts": {
"start": "npm-run-all -p build-css build-webpack"
}
}
Any NPM module referenced here "just works" (i.e. the path to the executable is resolved under the hood by NPM)
2) NPX
In newer versions of NPM (i.e. >= 5.2 or so), the "NPX" executable is provided. This has a similar effect to running commands inside an NPM script. You would run:
npx npm-run-all -p build-css build-webpack
Again, the path would be automatically resolved.
If you have an older NPM install, you can also install it separately:
npm install -g npx
npm install -g npm-run-all
Works for me.
Double check if npm-run-all is in your package.json devDependencies.
I had same problem while using code editor Brackets.
To resolve the error, I did the following steps.
Add nodejs new system variable to your PC under Control Panel -> System -> Advanced System Settings
;C:\Program Files\nodejs\
After that, re-run command:
npm
I don't know if this would help anyone, but I got this error because I was doing nodemon server.js instead of nodemon server/server.js. I wasn't in the right folder!
Did you reopen the terminal after you installed node?
If you have installed npm with the current terminal window open. Your terminal window will not have loaded the latest path settings (with npm location) to find the npm application to run the command. In this case try below steps .
Try closing the current terminal session.
Reopen a new session.
Try the command again ( will pick up the new path settings with npm installed)
This worked for me.
npm audit fix --force
Also you can try downgrading your autoprefixer, seems version 10.0.0 doesn't work well with postcss
npm i autoprefixer#9.8.6

'expo' is not recognized as an internal or external command

After running npm install -g expo-cli and successfully installing the packages globally, expo is still not recognized as an internal or external command. Does anyone know how I might get around this issue using windows 10, or what to do in terms of something like a path variable.
Probably the only thing missing is to add the expo executable to your path.
For Windows 10, you can simply add the npm folder to your path environment variable.
Hit Windows key and search for Environment variables.
Inside the Path variable under System variables, add a new
entry (entries are separated by semicolons) with this content (without /node_modules ):
%USERPROFILE%\AppData\Roaming\npm
OR if you are using yarn C:\Users\{USER}\AppData\Local\Yarn\bin (as #Qwerty mentioned above)
Open a new command prompt and enter
> expo
You will see something like this:
I may be too late to answer this, but for people looking for the same error this is what worked for me.
Install yarn if you don't have it. I used the command choco install yarn (you'll have to install Chocolatey). If you have scoop installed, scoop install yarn also works.
Use yarn to install expo with yarn global add expo-cli.
expo start should work now. yarn start and npm start should also work.
Hope that helps!
I wondered it was working last night when I first installed and run the "react-native" project but the very next day it showed me the same error as yours.
Here is what I did in windows 10 Operating System:
Add the following path :
environment variable > System Variables > PATH > C:\Users\YOUR_USERNAME\AppData\Roaming\npm
Now I ran the following commands one by one in CMD:
i) npm -g uninstall expo-cli --save
ii) npm install -g expo-cli
Now start the Project and run npm start and now it works for me.
I didn't try this article one but it also shows the solution for the same problem,
see here
Added These path of npm like this i have the same issue i fix it by adding the path to environment system
C:\Users\abobakr\AppData\Roaming\npm
After that close CMD and open it again it should work believe me
go to the environment variable, then in the user variable section find Path and press the edit button, you will see a new window, press new and add the following
%USERPROFILE%\AppData\Roaming\npm
then press ok. Now,
expo --version
Here is the solution I came out with.
I ran npm list -g
then copy the directory on the first line and paste in your system enviroment variables under the variable name 'path'
close all the terminals and run expo or any other command.
This worked for me :
Download latest version of nodejs - https://nodejs.org/en/download/
After installing nodejs reboot your computer
install : npm install --global expo-cli
Generate a new project with - npx expo-cli init projectName
cd projectName
npm start
If it still doesnt work or you can't access npm. Try setting the path with the Windows PowerShell:
Open Windows Powershell as Administrator
Type: setx path "%path%;C:\Users\USERNAME\AppData\Roaming\npm"
It worked for me.
Re-install node.js and
then run npm install -g expo-cli in command prompt.
If you are using Windows 10 or 11, the solution to edit your Path variable works well.
Just make sure that you replace "YOUR_USERNAME" with your username on the computer:
This means that if my username is "Green", I will replace YOUR_USERNAME here:
C:\Users\YOUR_USERNAME\AppData\Roaming\npm
to
C:\Users\Green\AppData\Roaming\npm.
This article is very detailed in solving the problem in case if the above does not work for you.
I had the same problem last night, and I've recently started my journey in ReactNative. So, there might be better answers out there.
If you're following the ReactNative Official documentation, the first time npm start works fine, the subsequent ones throws an error saying expo is not recognized. I got around that by running expo start and not npm start ( which basically is the same thing but doesn't work for some reason ).
So, mine looks like a work around rather than an explanation as to why this happens or how to permanently fix it.
For me,
i uninstalled node.js,
i re-installed node.js,
i ran npm install -g expo-cli,
then ran expo --version (the expo command began to work).
Hope this helps.
This worked for me:
You must uninstall node js then install it again.
You must run npm install expo-cli.
It will solve your problem
This is a more general problem where your global node modules are not in your system path. This question is what you are looking for: Nodejs cannot find installed module on Windows?
I have fixed this in Windows 10 by setting Path C:\Users\[USERNAME] this line save my hrs
uninstall expo using this command
npm -g uninstall expo-cli --save
and reinstall expo using this command
npm install -g expo-cli
then it will work properly
I faced same problem and it was not getting resolved by "npm install --global expo-cli".
Global CLI was having error as SS below -
npm list -g --depth 0
Followed below steps to get it resolved
npm uninstall --global expo-cli
Deleted global package causing error C:\Users<USERNAME>\AppData\Roaming\npm\node_modules\expo-cli
npm install --global expo-cli
And expo cli worked.
Happy coding!!!
If you need a solution to Run Expo command without Environment Variable update then on your terminal use below command for windows system:
R:\> C:\Users\{user}\AppData\Roaming\npm\expo.cmd init {projectname}
Where you directly point the expo.cmd file rather than specifying in the environment variable.
And update the expo to C:\Users{user}\AppData\Roaming\npm\expo.cmd in package.json to run the project.
// package.json
"scripts": {
"start": "C:\\Users\\{user}\\AppData\\Roaming\\npm\\expo.cmd start",
"android": "C:\\Users\\{user}\\AppData\\Roaming\\npm\\expo.cmd start --android",
"ios": "C:\\Users\\{user}\\AppData\\Roaming\\npm\\expo.cmd start --ios",
"web": "C:\\Users\\{user}\\AppData\\Roaming\\npm\\expo.cmdstart --web",
"eject": "C:\\Users\\{user}\\AppData\\Roaming\\npm\\expo.cmd eject"
},
If you are using yarn global add expo-cli, try npm install -g expo-cli.
I don't know why but when i go into C:\Users\%{user}%\AppData\Roaming\npm there isn't the expo package(and other packages that I thought I install globally by yarn) but there are other that I installed globally by npm.
If adding C:\Users\%{user}%\AppData\Roaming\npm to PATH variable doesn't work, give this a shot.
If you set the environment path as said in other replies and the command is still not recognized, try running whatever you're using to execute the command in administrator mode.
I'm using VS Code terminal and expo was not recognized until I ran it as administartor.

Failed to create app with create-react-app in Linux 16.04

I am trying to create new app with create-react-app.
Below is the error.
Please help. Thanks in advance
➜ REACT create-react-app my-app
Creating a new React app in /media/budi/Tjung/#TJUNG/REACT/my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
yarn add v1.6.0
info No lockfile found.
[1/4] Resolving packages...
error An unexpected error occurred: "http://registry.npmjs.org/react: > ETIMEDOUT".
info If you think this is a bug, please open a bug report with the information provided in "/media/budi/Tjung/#TJUNG/REACT/my-app/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Aborting installation.
yarnpkg add --exact react react-dom react-scripts --cwd /media/budi/Tjung/#TJUNG/REACT/my-app has failed.
Deleting generated file... package.json
Deleting generated file... yarn-error.log
Deleting my-app / from /media/budi/Tjung/#TJUNG/REACT
Done.
error image at CLI
Looks like network problem to me. You could be behind a proxy. If that is the case, configure your proxy in npm like this
npm config set proxy http://proxy_host:port
For https
npm config set https-proxy http://proxy.company.com:8080
Note: The https-proxy doesn't have https as the protocol, but http.
Optionally you can also try,
npm config set strict-ssl false
Checkout this SO answer
check if npm exists on your system.
try the commands in this order.
1. npm install --save create-react-app
2. create-react-app projectname
The name of the project must be in lowercase
Assuming that you have Node installed, you can use npm to install the create-react-native-app command line utility:
npm install -g create-react-native-app
Then run the following commands to create a new React Native project called "my-app":
create-react-native-app my-app
cd my-app
npm start
I have solve this problem.. it is about internet speed connection.
.
When I met this problem, I have spent one day to find out the solution. I read so many article about ETIMEDOUT. I had uninstall and re-install npm and yarn. Still doesn't solve my problem.
.
Until then I found the spot that has high speed internet connection. Fortunately I can create new app with create-react-app.
I think there are problem with your configurations of npm package.
Maybe somewhere, you set up some proxy configuration to npm variables.
You can reset configs running this script in terminal
sudo sh -c 'echo "" > $(npm config get globalconfig)'
and wait until process will end and run
exit
Open another terminal window and try

Express module not found when installed with NPM

When I try to run the app.js file created by express, I get the following error:
$ node app.js
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'express'
at Function._resolveFilename (module.js:320:11)
When I type in express --version I get a return statement of 2.3.3. I used npm to install express. I had to manually make npm using these instructions:
git clone http://github.com/isaacs/npm.git
cd npm
sudo make install
The error is Error: Cannot find module 'express'.
Do I need to do something after installing npm and express in order to make express see the modules created by npm?
My node is version: 0.4.6
My express is version: 2.3.3
My npm is version: 1.0.6
Express is installed globally. I used the -g flag to install it.
Edit: When I try "node -e require.paths" I get:
[ '/home/user/.node_modules',
'/home/user/.node_libraries',
'/usr/local/lib/node' ]
So, node isn't detecting the npm installation. How do I get node to detect the npm installation?
Install express
npm install -g express
Create a new app
express your_app
cd into app directory
cd your_app
use npm link to resolve modules
npm link express
Use local installs for require(), and global installs for command-line apps.
If you need both, use the npm link command.
On Ubuntu 12.04 you have to add the export NODE_PATH=/usr/local/lib/node_modules to your /.bashrc to use globally installed modules.
It appears that while npm had been updated to install global modules into /usr/local/lib/node_modules, Node's own require.paths does not yet reflect this change.
There are two reasonable solutions:
Add the following code to the top of your application:
require.paths.push('/usr/local/lib/node_modules');
Pro: non-invasive, easy to add
Con: requires discipline, future versions of node will restrict access to require.paths
As root, execute:
ln -s /usr/local/lib/node_modules /usr/local/lib/node
Pro: reasonably non-invasive
Con: requires root, modifies linux fs, might not survive system updates
I had the same problem. This worked for me though:
Seems like npm (now?) installs node modules to /usr/local/lib/node_modules/ and not /usr/local/lib/node/
What I did was simply to copy everything from node_modules to node: sudo cp -r /usr/local/lib/node_modules/* usr/local/lib/node/ and now it seems to be working for me.
Hope this helps you :-)
What about NODE_PATH=/usr/local/lib/node_modules in .bashrc or .bash_profile? I think it's the real correct way.
Set NODE_PATH=NODE_HOME\node_modules.
I'm using windows 7 and it works fine.
It may happen, if you're using windows, that the environment variable NODE_PATH is not set, and thus when you execute node fileName.js it won't find the libraries.
Check for the variable on your console, and if not present, create it. Give it the NODE_HOME\node_modules value, where NODE_HOME is your node install dir. This path is where npm install puts every module upon downloading.
require.paths is removed, use the NODE_PATH environment variable instead.
It looks like the easiest way to do this is to run npm install from your app's folder. This tells npm to hook everything up.
It's the last instruction after express <appname>:
...
dont forget to install dependencies:
$ cd <appname> && npm install
Finally with Linux a good way to do is to use the command : sudo apt-get install node-express
But with express 4 we must use express-generator to make app skeleton, install it with 'npm install express-generator -g', and then run 'express myapp' command.
see also install express
for mac users
cd /usr/local/lib/node
sudo ln -s ../node_modules/* ./$1
I installed gulp and when I ran this gulp command in the command line I got a gulp: command not found error. It appeared that it installed gulp in my local folder that is /home/YOURUSERNAME/.node/lib/node_modules and not in the global npm folder.
You can check npm root folder by running this command: npm root -g, which was returning my personal directory /home/YOURUSERNAME/.node/lib/node_modules and not the expected /usr/local/lib/node_modules.
You can fix this by running npm config set prefix /usr/local command.
For all problems with express with a mac computer:
The solution is:
chown to your user the .npm folder :
sudo chown -R Webmaste /Users/webmaste/.npm/
At your test folder or your folder:
sudo npm install -g express#2.5.8
Invoke express from your actual location:
/usr/local/share/npm/bin/express
sudo cd . && npm install
Finally:
node app
the final message in the console should look like this:
Express server listening on port 3000 in development mode

Categories

Resources