【问题标题】:I'm having a problem that can't create react app using npx command我遇到了无法使用 npx 命令创建反应应用程序的问题
【发布时间】:2020-04-25 16:44:15
【问题描述】:

我无法使用 npx create-react-app <projectname> 创建我的 react 项目。

控制台给出这个:

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.

【问题讨论】:

    标签: node.js reactjs npx


    【解决方案1】:

    在安装 create-react-app 之前清理您的 npm 缓存。

    npm cache clean --force
    

    然后全局安装create-react-app

    npm install -g create-react-app
    

    然后您可以使用 create-react-app 创建您的 React 应用程序

    create-react-app my-app
    

    然后导航到my-app 并运行

    npm start
    

    【讨论】:

    • 干杯@TrevorWong
    猜你喜欢
    • 2020-07-14
    • 2020-10-31
    • 2022-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-06
    • 1970-01-01
    相关资源
    最近更新 更多