问题
I can't use npx create-react-app <projectname>
to create my react project.
The console give out this:
Must use import to load ES Module: C:\Users\user\AppData\Roaming\npm-cache\_npx\4536\node_modules\create-react-app\node_modules\is-promise\index.js //
require() of ES modules is not supported. //
require() of C:\Users\user\AppData\Roaming\npm-cache\_npx\4536\node_modules\create-react-app\node_modules\is-promise\index.js from C:\Users\user\AppData\Roaming\npm-cache\_npx\4536\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 C:\Users\user\AppData\Roaming\npm-cache\_npx\4536\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 C:\Users\user\AppData\Roaming\npm-cache\_npx\4536\node_modules\create-react-app\node_modules\is-promise\package.json.
回答1:
Clean your npm
cache before installing create-react-app
.
npm cache clean --force
Then install create-react-app
globally.
npm install -g create-react-app
Then you can create your react app using create-react-app
create-react-app my-app
Then navigate to my-app
and run
npm start
来源:https://stackoverflow.com/questions/61429120/im-having-a-problem-that-cant-create-react-app-using-npx-command