2

I've just finished installing create-react-app successfully. But, when I create a new project like below command, error happens. Could you please give me a recommandation?

system env.: - aws lightsail 1vcpu, 0.5G ram / ubuntu 18.04 - nodejs version : 13.9.0 - npm version : 6.13.7 - create-react-app version : 3.4.0

~$ npm create-react-app my-app

Installing packages. This might take a couple of minutes. Installing react, react-dom, and react-scripts with cra-template...

core-js@2.6.11 postinstall /home/ubuntu/my-app/node_modules/babel-runtime/node_modules/core-js node -e "try{require('./postinstall')}catch(e){}"

Aborting installation. npm install --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.

Deleting generated file... node_modules Deleting generated file... package.json

Done.

sungon
  • 21
  • 1
  • 2

3 Answers3

2

Switch to Yarn

It was a raised issue on github a couple of years back.. it was solved after switching to yarn. These commands could not solve the issue.

npm cache clean --force
create-react-app my-apps

Switching to Yarn worked!

npm install -g yarn
yarn global add create-react-app
create-react-app my-app

See if this helps!

Community
  • 1
  • 1
Aditya Patnaik
  • 1,490
  • 17
  • 27
  • Aditya issue is not with `yarn` or any other package installer. It is related to `create-react-app` command itself. – Alfha Sep 17 '21 at 04:13
  • You are right. But if you could go through the discussions under the closed issue https://github.com/facebook/react/issues/11933, the conclusion was switching to yarn to get it work. This a work around. If this is fixed by now in the cra , suggest an edit to this answer. Thanks – Aditya Patnaik Sep 18 '21 at 05:23
  • Even in Linux, using `yarn`, a wrong bash path is assumed as `core-js` tries to run script inside `SHELL`, so your alternative solution is not a universal solution, ultimately one has to find how to deal with `facebook/create-react-app` mess! – Alfha Sep 18 '21 at 05:44
2

This error is due to the fact that a dependant module named core-js is trying to run a post-install script. This post-install script spawns a child process and runs a shell script there. For some reason Node sets/assumes a wrong bash path by default. I had to manually change the path by running the following command.

npm config set script-shell $(which sh)

Note: For Windows you might have to setup your own bash.exe by installing something like git-bash and then you could assign the path similarly.

David Brossard
  • 13,584
  • 6
  • 55
  • 88
Leo Allen
  • 31
  • 3
  • thank you this worked for me, I also found this question related on how to set it, if it helps: https://stackoverflow.com/a/46006249/10945921 – travs15 Oct 10 '22 at 16:05
0

Try this: npm cache clean --force