0

Here is the command that I ran to try to create a React app and the resulting error log. I have been able to successfully run it three times before with the command $ npx create-react-app, but now every time that I run it, it does not work and instead returns an error related to ES modules. I have been experimenting with many ways to integrate React with Django, but I don't think that I edited any core files in doing so that would have caused this error. I am completely new to React and Node.js so any advice would be greatly appreciated.

npx: installed 99 in 7.591s
Must use import to load ES Module: /Users/(username)/.npm/_npx/27993/lib/node_modules/create-react-app/node_modules/is-promise/index.js
require() of ES modules is not supported.
require() of /Users/(username)/.npm/_npx/27993/lib/node_modules/create-react-app/node_modules/is-promise/index.js from /Users/(username)/.npm/_npx/27993/lib/node_modules/create-react-app/node_modules/run-async/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /Users/(username)/.npm/_npx/27993/lib/node_modules/create-react-app/node_modules/is-promise/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/(username)/.npm/_npx/27993/lib/node_modules/create-react-app/node_modules/is-promise/package.json.```
Jack
  • 13
  • 2

2 Answers2

0

This seems to be a recent problem with npm. There is an issue open as of the last few hours and it seems like people are working on it. I don't think it's anything to do with your Django/React project.

The issue ticket

While the issue is being fixed: try installing node version 12.12.0 as shown below and run create-react-app again.

nvm install 12.12.0
nvm use 12.12.0
msmoore
  • 396
  • 2
  • 12
0

it is a problem from node, Either you have to downgrade you node version or you can use Yarn try the following: So, apparently the issue is from npm and non of us has done anything wrong, still we can use Yarn to start a new react project while they solve it, follow the steps:

step 1: yarn init -y

step 2: Insert this to package.json

"resolutions": { "is-promise": "2.1.0", "run-async/is-promise": "2.1.0" }

step 3: yarn add --dev create-react-app

step 4: yarn create-react-app ../my-app

Sam AlGhamian
  • 73
  • 2
  • 12