【问题标题】:React Typescript: It looks like you're trying to use TypeScript but do not have typescript installedReact Typescript:看起来你正在尝试使用 TypeScript 但没有安装 TypeScript
【发布时间】:2022-12-20 02:04:21
【问题描述】:

我想创建一个 React 应用程序,我想在这个应用程序中使用 typescript,起初我去 React 网站是为了使用 typescript 创建一个应用程序,我发现我必须先在终端中输入这条指令:

npx create-react-app my-app --template typescript

安装完成后,我将其放入终端:

npm start

但是我得到了这个错误:

It looks like you're trying to use TypeScript but do not have typescript installed

我打开终端并写了这条指令:

npm install

然后我运行应用程序:

npm start 

但错误仍然存​​在

我该如何解决这个问题?

【问题讨论】:

    标签: reactjs typescript


    【解决方案1】:

    我按照以下说明解决了我的问题:

    npm install --save typescript @types/node @types/react @types/react-dom @types/jest
    

    或者

    yarn add typescript @types/node @types/react @types/react-dom @types/jest
    

    【讨论】:

    • 确保检查您在 package.json 中使用的 React 版本。我在尝试将打字稿添加到 React17 项目时收到“它看起来像..”错误。我必须将我的@types 固定到版本 17。例如: npm install --save-dev typescript @types/react@17.0.0 @types/node@17.0.0 @types/react-dom@17.0.0
    【解决方案2】:

    你有没有尝试过

    npm install -g typescript
    

    是的,我试过了,但仍然有错误

    你有没有尝试过

    npm run start
    

    【讨论】:

      【解决方案3】:

      考虑将 Next.js 11 升级到 12 或最新版本。此外,您需要将类型升级到最新版本以进行反应和反应-dom。这是关于它的简短文档:

      https://nextjs.org/docs/upgrading#upgrade-nextjs-version-to-12

      【讨论】:

        猜你喜欢
        • 2022-08-22
        • 1970-01-01
        • 2020-08-04
        • 1970-01-01
        • 2021-11-17
        • 2020-07-11
        • 2021-04-08
        • 2021-03-18
        • 2019-06-06
        相关资源
        最近更新 更多