Error while using create react app command - javascript

Even though everything used to work couple of weeks ago, now I can not successfully create new react app with its templates.
When I try to run npx create-react-app my-app command, it only creates the folder with package.json, pckage-lock.json and node_modules. The public folder is missing and also, when I try to run npm start, it gives me an error saying:
npm ERR! missing script: start
npm ERR! A complete log of this run can be found in:
before it used to say happy hacking and the template page with react logo was displayed.
I tried to uninstall and install node again, clear cache but nothing helped. Any advice? Thank you so much!
My npm -v is 6.13.4 and node -v is v12.14.0

If you have installed create-react-app globally. remove that globally from you system
Try these steps
npm uninstall -g create-react-app
npx create-react-app app_name
cd app_name
npm start
Note- npx comes with npm 5.2+ and higher, see instructions for older
npm versions
Check this reactjs documentation.

Faced the same issue and fixed it by following the below steps:
Try to uninstall all existing global installation of create-react-app and check that they are removed properly by using the two commands below:
command for uninstalling: npm uninstall -g create-react-app
command for checking: which create-react-app
command for manual delete: rm -rf <path where create react app is located>
Once all the versions are removed, use: npx create-react-app <name_of_the_app>
For more details refer here

First, update the npm and node using following commands:
npm install -g npm
npm cache clean -f
npm install -g n
n stable
Remove globally installed create-react-app using:
npm uninstall -g create-react-app
Use npx for using create-react-app directly:
npx create-react-app <project-name>

I was having the same issue, and saw a lot of the same answers saying to uninstall create-react-app globally and reinstall using npx create-react-app my-app.
Downgrading my version of Node to 8.11.1 is what fixed it.
sudo npm install -g n
sudo n 8.11.1
node -v
> v8.11.1
After that I ran npx create-react-app my-app and it worked as expected.

Related

Reactjs stuck at installing react Dom,react-templates

I have installed nodejs then I tried to create react is app using npx create-react-app my-app but it just stuck in installing react-dom,cra-templates and then I tried npm also but it's the same please help need to learn react js please help
I have node version v16.13.2.
and npm version 8.1.2
PS D:\Programming\React Js> npx create-react-app firstapp
Creating a new React app in D:\Programming\React Js\firstapp.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
You can try to install globally, generally there are no more problems after. To install run this command
npm install -g create-react-app
Once installation successful, try running
npx create-react-app my-app
You likely have a global installation of create-react-app which is not the latest version. Uninstall it using npm uninstall -g create-react-app.
The CRA docs recommend uninstalling the global version in their very first steps:
If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app or yarn global remove create-react-app to ensure that npx always uses the latest version.

Error then trying create-react-app( npm ERR! cb() never called! then trying create-react-app)

Have some troubles then trying create react app
PS D:\Projects\Test> npx create-react-app my-app
Creating a new React app in D:\Projects\Test\my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://npm.community>
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\semen\AppData\Roaming\npm-cache\_logs\2022-01-05T05_29_35_153Z-debug.log
Aborting installation.
npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.
I reinstalled nodejs few times. Made downgrade nodejs to 14.18.1 version. Tryed to used Yarn. But this soltushions dont work in my situation. I use Windows 10.
Thanks for help!
I had the same error after I created my React app and couldn't install any more packages.
Try clearing your cache with npm cache verify or npm cache clean --force.
If that doesn't work, then try doing a clean install of npm using:npm clean-install.
This error has happened to me before and I have followed these steps, I hope it works for you too.
The first thing you need to do is to uninstall the create-react-app and then npm install it again.
You can use these commands for uninstalling the create-react-app:
if you are using NPM:
npm uninstall -g create-react-app
if you are using Yarn:
yarn global remove create-react-app
for creating a new app you can use the following command:
npx create-react-app#latest your-project-name
You must notice that the create-react-app should not be installed globally as it is documented in Create-React-app Docs.
Also please note that it is safe to say, always use the LTS version of node (that is 16.13.2 at this time).
It should solve your problem with initiating a new react app.

create-react-app Error: Cannot find module 'react-scripts/scripts/init.js'

Everytime I try to create a brand new project with create-react-app I get this error:
Error: Cannot find module 'react-scripts/scripts/init.js'
Screenshot
THE WAY I CREATE PROJECT:
npx create-react-app new-project
node -v v12.13.1
npm -v 6.12.1
OS Win10
already tried:
npm uninstall -g create-react-app
different project paths
by the way:
the problem disappears when I use --use-npm flag
Any ideas what the reason can be?
Open your command prompt and type "node -v" as well as "npm -v", What do you get there as a response?
Here i found an answer to the same issue, https://stackoverflow.com/a/63334241/7857368
have your tried creating the app with npx create-react-app myapp you don't need to install the create-react-app globally anymore with this command.
Try running the following commands:
npm install
npm install react-scripts
npx create-react-app App-name
React-scripts issue is issue with webpack and babel mostly. You should
create a brand new project using npx create-react-app projectName and this is the recommended approach. This way you don't have to globally install create-react-app in your machine which was previous approach.
Have a look at the documentation. https://reactjs.org/docs/create-a-new-react-app.html
NOTE:
For npx create-react-app projectNameto work. Your node and npm
should be: Node >= 8.10 and npm >= 5.6
And you will have to uninstall old create-react-app from the
machine. See the doc: https://create-react-app.dev/docs/getting-started

I am getting an error while trying to install new React App [duplicate]

When I type the create-react-app my-app command in my terminal, it appears to work - downloading all libraries successfully etc. At the end of that process however I get a message that a template was not provided.
Input
user#users-MacBook-Pro-2 Desktop% create-react-app my-app
Output
Creating a new React app in /Users/user/Desktop/my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
..... nothing out of the ordinary here .....
✨ Done in 27.28s.
A template was not provided. This is likely because you're using an outdated version of create-react-app.
Please note that global installs of create-react-app are no longer supported.
In package.json of my-app:
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.0" <-- up-to-date
}
I checked out the CRA changelog and it looks like support was added for custom templates - however it doesn't look like the command create-react-app my-app would have changed.
Any idea what is going on here?
If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version.
Docs
Use either one of the below commands:
npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app
if npm uninstall -g create-react-app stated above does not work.
Type which create-react-app to know where it is installed. Mine was installed in /usr/bin folder. Then do sudo rm -rf /usr/bin/create-react-app. (Credit to #v42 comment below)
1)
npm uninstall -g create-react-app
or
yarn global remove create-react-app
2)
There seems to be a bug where create-react-app isn't properly uninstalled and using one of the new commands lead to:
A template was not provided. This is likely because you're using an
outdated version of create-react-app.
After uninstalling it with npm uninstall -g create-react-app, check whether you still have it "installed" with which create-react-app (Windows: where create-react-app) on your command line. If it returns something (e.g. /usr/local/bin/create-react-app), then do a rm -rf /usr/local/bin/create-react-app to delete manually.
3)
Then one of these ways:
npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app
Though already lots of answer is here.
I came up with 3 solutions which I applied step by step when I faced this situation.
First step: From Official manual,
If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version.
https://create-react-app.dev/docs/getting-started
You can use these commands below:
npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app
Second step (If first one doesn't work):
Sometimes it may keep caches.then you can use these commands given below.
npm uninstall -g create-react-app
npm cache clean --force
npm cache verify
yarn create react-app my-app
Third step:(If these 2 won't work)
first uninstall via npm uninstall -g create-react-app,then check if you still have it "installed" with which create-react-app command on your command line. If you got something like (/usr/local/bin/create-react-app) then run this rm -rf /usr/local/bin/create-react-app (folder may vary) to delete manually.
Then again install it via npx/npm/yarn.
NB: I succeed in the last step.
First uninstall create-react-app globally by this command:
npm uninstall -g create-react-app
then in your project directory:
npm install create-react-app#latest
finally:
npx create-react-app my-app
To add up more to the answers above:
With the new release of create-react-app, you can create a new app using custom templates.
Two templates available so far:
cra-template
cra-template-typescript
Usage:
npx create-react-app my-app [--template typescript]
More details of the latest changes in create-react-app:
https://github.com/facebook/create-react-app/releases/tag/v3.3.0
I too had the same problem. When I trid the npm init react-app my-app command returned the same message
A template was not provided. This is likely because you're using an
outdated version of create-react-app.
But
yarn create react-app my-app command works fine.
Clear your npm cache first then use yarn as follows:
npm cache clean --force
npm cache verify
yarn create react-app my-app
I hope this helps.
EDIT
...you might want to try the following after I have looked into this problem further:
npm uninstall -g create-react-app
yarn global remove create-react-app
which create-react-app - If it returns something (e.g. /usr/local/bin/create-react-app), then do a rm -rf /usr/local/bin/create-react-app to delete manually.
npm cache clean --force
npm cache verify
npx create-react-app#latest
These steps should remove globally installed create-react-app installs, you then manually remove the old directories linked to the old globally installed create-react-app scripts. It's then a good idea to clear your npm cache to ensure your not using any old cached versions of create-react-app. Lastly create a new reactjs app with the #latest option like so: npx create-react-app#latest. There has been much confusion on this issue where no template is created when using npx create-react-app, if you follow the steps I have stated above (1-6) then I hope you'll have success.
p.s.
If I wanted to then create a react app in a directory called client then I would type the following command into the terminal:
npx create-react-app#latest ./client
Good luck.
npm install -g create-react-app in your pc
create react project again with npx create-react-app my-app
This worked for me.
npm uninstall -g create-react-app
npx create-react-app my-app
So I've gone through all the steps here, but non helped.
TLDR; run npx --ignore-existing create-react-app
I am on a Mac with Mojave 10.15.2
CRA was not installed globally - didn't find it in /usr/local/lib/node_modules or /usr/local/bin either.
Then I came across this comment on CRA's github issues. Running the command with the --ignore-existing flag helped.
These two steps worked for me
1) Uninstalled react-app globally with this command
npm uninstall -g create-react-app
2) Installed react-app in project folder with this command
npx create-react-app project-name
npx create-react-app#latest your-project-name
work for me after trying all the answers hope that can help someone in the future.
"If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version"
This is reported at https://create-react-app.dev/docs/getting-started/. For me, this did not work. I had to re-install create-react-app globally instead.
My steps to fix this problem were to:
npm uninstall -g create-react-app
npm install -g create-react-app
npx create-react-app my-app
All of the option didn't work for me on MacOS. What did work was the following 3 steps:
Delete the node from: /usr/local/bin/
then
install node newly: https://nodejs.org/en/
then
Install react: npx create-react-app my-app follow: https://create-react-app.dev/
For Linux this worked for me
sudo npm uninstall -g create-react-app
npx create-react-app my-test-app
TLDR: Uninstall the global package using npm uninstall -g create-react-app and generate new react apps using npx create-react-app app.
Issue
You're using an older version of create-react-app that you have installed globally using npm. The create-react-app command invokes this global package.
You could've confirmed that you were using an outdated version by running npm outdated -g create-react-app or comparing create-react-app --version with npm view create-react-app.
The fact that the version of react-scripts was up to date, has nothing to do with the version of the package that is bootstrapping the app (create-react-app), which grabs the latest versions of the packages that it uses (react-scripts in this case).
Solution
If you want to continue using the create-react-app command, you'll need to update the global package using npm update -g create-react-app. Note that you'll want to do this periodically to keep it up to date. You'll notice that create-react-app does not recommend this (noted in the logs from your install).
A better approach would be to delete the global install entirely (npm uninstall -g create-react-app) and instead use npx so that it grabs the latest version of the package every time (more detail on npx below).
You should confirm that it was uninstalled globally by trying to use create-react-app to make sure the command is "not found".
Issues with uninstalling?
You can debug where it was installed using which create-react-app. If you're having issues uninstalling it, you may have multiple versions of node/npm on your machine (from multiple installs, or because you use a node version manager such as nvm). This is a separate issue I won't address here, but there's some info in this answer.
A quick nuclear approach would be to forcefully remove it (rm -rf) at the path that which create-react-app returns.
Supplement
Global npm packages and the npx command
$ NPM_PACKAGE_NAME will always use the globally installed version of the package, regardless of which directory you're in.
$ npx NPM_PACKAGE_NAME will use the first version of the package that it finds when searching up from the current directory to the root:
If you have the package in your current directory, it will use that.
Else if you have the package in a directory that is a parent of your current directory, it will use the first one it finds.
Else if you have the package installed globally, it will use that.
Else if you don't have the package at all, it will temporarily install it, use it, and then discard it. - this is the best way to ensure the package is up to date.
More info about npx can be found in this answer.
Using npx with create-react-app
create-react-app has some special commands/aliases to create a react app (instead of npx) that are specific to that package (yarn create react-app, npm init react-app), but npx create-react-app will work the same as it does with other packages.
yarn vs npm global installs
Yarn stores global installs in a different folder than npm, which is why yarn create react-app would work immediately without uninstalling the global npm package (as far as yarn is concerned, the package hasn't been installed).
This is just a temporary solution though, as you'll need to remember to always use yarn instead of npm when using Create React App.
This works for me!
1) npm uninstall -g create-react-app
2) npm install -g create-react-app
3) npx create-react-app app_name
If you have any previously installed create-react-app globally via npm install -g create-react-app, Better to uninstall it using npm uninstall -g create-react-app
This solved my problem
Steps:
1.Uninstall the create-react app
npm uninstall -g create-react-app
2.Now just use
npx create-react-app my-app
this will automatically create the template for u .
This problem is not solved like this, the problem is in the different instances of node, try removing globally create-react-app and then delete the node_modules and package-lock.json from your root user
This work's for me :
Let's, uninstall create-react-app globally by this command:
npm uninstall -g create-react-app
After that in your project directory:
npm install create-react-app#latest
At the last:
npx create-react-app my-app
For typescript :
npx create-react-app my-app --template typescript
First uninstall create-react-app
npm uninstall -g create-react-app
Then run yarn create react-app my-app or npx create-react-app my-app
then running yarn create react-app my-app or npx create-react-app my-app may still gives the error,
A template was not provided. This is likely because you're using an outdated version of create-react-app.Please note that global installs of create-react-app are no longer supported.
This may happens because of the cashes. So next run
npm cache clean --force
then run
npm cache verify
Now its all clear. Now run
yarn create react-app my-app or npx create-react-app my-app
Now you will get what you expected!
I fix this issue on Mac by uninstalling create-react-app from global npm lib, that's basically what said, just try to do, you need also do sudo:
sudo npm uninstall -g create-react-app
Then simply run:
npx create-react-app my-app-name
Now should be all good and get the folder structures as below:
Using the command npm uninstall -g create-react-app didn't work for me.
But this worked:
yarn global remove create-react-app
and then:
npx create-react-app my-app
Such a weird problem because this worked for me yesterday and I came across the same error this morning. Based on the release notes, a new feature was added to support templates so it looks like a few parts have changed in the command line (for example, the --typescript was deprecated in favor of using --template typescript)
I did manage to get it all working by doing the following:
Uninstall global create-react-app npm uninstall create-react-app -g.
Verify npm cache npm cache verify.
Close terminal. I use the mac terminal, if using an IDE maybe close and re-open.
Re-open terminal, browse to where you want your project and run create-react-app via npx using the new template command conventions. For getting it to work, I used the typescript my-app from the documentation site to ensure consistency: npx create-react-app my-app --template typescript
If it works, you should see multiple installs: one for react-scripts and one for the template. The error message should also no longer appear.
npm uninstall -g create-react-app could be an answer in some cases, but not in mine.
You should manually delete your create-react-app located at ~/.node/bin/ or /usr/bin/ (just type which create-react-app and remove it from locations you saw using rm -rf), next just run npm i -g create-react-app.
After that create-react-app will be working correctly.
This worked for me
1.First uninstall create-react-app globally by this command:
npm uninstall -g create-react-app
If there you still have the previous installation please delete the folder called my app completely.(Make sure no program is using that folder including your terminal or cmd promt)
2.then in your project directory:
npm install create-react-app#latest
3.finally:
npx create-react-app my-app
For any Windows users still having this issue, this is what fixed it for me:
Run where create-react-app to get the path (mine was in C:\Users\username\AppData\Local\Yarn\bin).
Navigate to that directory and delete both "create-react-app" and "create-react-app.cmd".
Navigate to the directory you want to start a project in.
Run npm install create-react-app,
npx create-react-app name-of-app,
cd name-of-app, yarn start.
Step #4 will vary based on your configuration, but that's just what got me up and running.
One of the easiest way to do it is by using
npx --ignore-existing create-react-app [project name]
This will remove the old cached version of create-react-app and then get the new version to create the project.
Note: Adding the name of the project is important as just ignoring the existing create-react-app version is stale and the changes in your machines global env is temporary and hence later just using npx create-react-app [project name] will not provide the desired result.
npx create-react-app#latest {project name}
this seems to be the way to make it work.
After using this command:
yarn global upgrade create-react-app
I then tried:
yarn create-react-app my-app but it didn't work for me.
This worked though:
npx create-react-app my-app

nest Command not found

I followed the documentation to create my first NestJS project.
Installing the Nest CLI with the command npm i -g #nestjs/cli was successful.
The output was:
+ #nestjs/cli#6.3.0
updated 1 package in 11.326s
However, when I try to scaffold a project with the Nest CLI:
nest new project-name
I get the following error:
zsh: command not found: nest
Some details about my environment:
OSX
iTerm
npm version 6.5.0
Use npx #nestjs/cli instead of nest
e.g. npx #nestjs/cli g controller pages
I was also getting the same console error when npm installing!
Erro was
#nestjs/cli
npm WARN deprecated resolve-url#0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix#0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated chokidar#2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated fsevents#1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/#nestjs/cli
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/#nestjs
npm WARN notsup Unsupported engine for watchpack-chokidar2#2.0.0: wanted: {"node":"<8.10.0"} (current: {"node":"12.14.1","npm":"6.13.4"})
npm WARN notsup Not compatible with your version of node/npm: watchpack-chokidar2#2.0.0
How I wasn able to install =>
Solution
sudo npm install -g #nestjs/cli
Following command works in my windows 10
node -v
v14.16.0
npm -v
6.14.11
npx #nestjs/cli new project-name
I was having the same issue, what I did was:
Installed the latest node with npm install npm#latest -g
and then added the following to my .bash_profile
alias nest="/usr/local/Cellar/node/11.9.0/bin/nest"
Tested with nest --version and it worked.
For some reason the path is not being called correctly, hope it helps.
Working through a NestJS/Mongo DB tutorial i stumbled into this very same problem. After trying all of the solutions that were listed above, even turning my default profile back to bash instead of using zsh, i found that simply adding the /usr/local/bin and ~/.npm-global/bin to my path variable resolved the issue. Hopefully this helps someone else who may stumble on this in the future as well.
export $PATH="/usr/local/bin"
export $PATH="~/.npm-global/bin"
Were the two commands i ran from iTerm2 in order to add them to my PATH environment variable. Once this was done a simple
env
showed the entries in my $PATH environment variable and the nest -v command worked without any issues.
I had same error when I use GitBash.
I resoved it:
If you use windows:
Your use CMD: npm i -g #nestjs/cli
Then you can use gitbash:
Check version nestjs: nest --version
Create app nestjs: nest new name_project
I have faced same problem and solved ,following this
write the command NPM root -g
check where NPM is installed
add it to your path environment variable
You have to add the following line to your ~/.zshrc file:
source $HOME/.bashrc
This is needed so that the npm binaries are available on startup.
After all the answers that I tried, I used my method
After installing npm i -g #nestjs/cli in my mac terminal.
open bash file in macos by typing open ~/.bash_profile in mac terminal. Like you can type it anywhere.
Your bash will look like this and use this line
alias nest="~/.npm-global/lib/node_modules/#nestjs/cli/bin/nest.js"
Restart your mac for changes to be reflected in your terminal.
There you go nestjs cli is now working globally 2nd screenshot.
I have just succeeded with
npx #nets/cli new project
when asked what manager to choose from npm / yarn / pnpm
made choice for pnpm
cd project
npm run start
Take care!
Must use sudo in comandline for linux, otherwise the command nest cannot be add to /usr/local/bin folder:
sudo npm install -g #nestjs/cli
You can try to use sudo
sudo yarn global add #nestjs/cli
I got the same issue.
I just uninstalled and reinstalled nextjs.
Finally, I can use next -v

Categories