【问题标题】:Next.js is not recognizing '@types/react'Next.js 无法识别 \'@types/react\'
【发布时间】:2022-08-02 21:18:10
【问题描述】:

当我尝试使用 npm run dev 运行我的 Next.js 应用程序时,我收到一条错误消息,指出我没有使用 Typescript 运行 Next 所需的包:

Please install @types/react by running:

        npm install --save-dev @types/react

If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files in your pages directory).

但是,模块 \'@types/react\' 已安装。我尝试运行npm install --save-dev @types/react 并没有收到任何错误消息(只是一堆警告,但我不认为它们是问题所在)。

我该如何解决这个问题并运行项目?

    标签: javascript reactjs typescript npm next.js


    【解决方案1】:

    似乎当前的@types/react 版本(特别是 v18.0.2)中存在错误,您可以使用npm install --save-dev @types/react@18.0.1 降级到 18.0.1

    来源:https://github.com/vercel/next.js/issues/36085

    【讨论】:

      【解决方案2】:

      我使用了yarn add -D @types/react@18.0.1,效果很好! Netsu 是对的,似乎当前的 @types/react 版本(特别是 v18.0.2)中存在错误。

      【讨论】:

        【解决方案3】:

        我的解决方案是将 --only 添加到生产中:

        运行纱线安装 --only=production

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-01-22
          • 2022-06-16
          • 2022-07-22
          • 2016-11-06
          • 1970-01-01
          • 2022-12-19
          • 2016-10-03
          • 2021-04-27
          相关资源
          最近更新 更多