【问题标题】:npx create-react-app command does not work, returns ES module error insteadnpx create-react-app 命令不起作用,而是返回 ES 模块错误
【发布时间】:2020-04-25 17:10:22
【问题描述】:

这是我尝试创建 React 应用程序时运行的命令以及生成的错误日志。我之前使用命令$ npx create-react-app 已经能够成功运行它三次,但是现在每次运行它时,它都不起作用,而是返回与 ES 模块相关的错误。我一直在尝试将 React 与 Django 集成的多种方法,但我认为我没有编辑任何会导致此错误的核心文件。我对 React 和 Node.js 完全陌生,因此非常感谢任何建议。

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.```

【问题讨论】:

    标签: node.js django reactjs npm npx


    【解决方案1】:

    这似乎是最近的 npm 问题。在过去的几个小时内有一个问题悬而未决,似乎人们正在解决这个问题。我认为这与您的 Django/React 项目无关。

    The issue ticket

    在解决问题时:尝试安装节点版本 12.12.0,如下所示,然后再次运行 create-react-app。

    nvm install 12.12.0
    nvm use 12.12.0
    

    【讨论】:

      【解决方案2】:

      这是节点的问题,您必须降级您的节点版本,或者您可以使用 Yarn 尝试以下操作: 所以,显然问题出在 npm 上,我们没有人做错任何事,但我们仍然可以在他们解决问题时使用 Yarn 启动一个新的 react 项目,请按照以下步骤操作:

      第 1 步:纱线初始化 -y

      第 2 步:将其插入 package.json

      “决议”:{ “是承诺”:“2.1.0”, “运行异步/是承诺”:“2.1.0” }

      第 3 步:纱线添加 --dev create-react-app

      第 4 步:yarn create-react-app ../my-app

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-06-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-15
        • 2021-06-17
        • 2020-08-11
        • 1970-01-01
        相关资源
        最近更新 更多