I'm having a problem that can't create react app using npx command

天大地大妈咪最大 提交于 2020-08-20 12:08:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!