【问题标题】:Can't create React Typescript application无法创建 React Typescript 应用程序
【发布时间】:2019-10-03 18:35:51
【问题描述】:

当我在 cmd 中执行命令时:

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

似乎应用程序将是打字稿,但是当我在 VS-code 中打开文件夹时,我会发布 src 文件夹中的所有文件都带有 .js 扩展名而不是 .ts(.tsx) 扩展.. 我尝试通过 cmd(管理员模式)创建应用程序,但没用,没有更改。我也尝试了命令:

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

还是什么都没有。

没有错误。应用就像标准的 react+js 应用一样工作。

【问题讨论】:

    标签: reactjs typescript create-react-app


    【解决方案1】:

    试试:

    npx create-react-app my-app --scripts-version=react-scripts-ts
    

    或:

    yarn create react-app my-app --scripts-version=react-scripts-ts
    

    【讨论】:

    • 谢谢!应用程序启动没有任何问题,但文件 App.tsx 显示代码中有一些错误,例如“无法访问的代码检测”?
    【解决方案2】:

    我也遇到了同样的错误,按照上面的建议尝试了npx create-react-app my-app --scripts-version=react-scripts-ts,得到了以下错误:

    ✔ 不推荐使用 react-scripts-ts 包。现在 Create React App 原生支持 TypeScript。在生成包含 TypeScript 支持的应用程序时,您可以改用 --template typescript 选项。你想继续使用 react-scripts-ts 吗? … 是的 安装软件包。这可能需要几分钟。 使用 cra-template 安装 react、react-dom 和 react-scripts-ts...

    npm 错误! cb() 从未调用过!

    npm 错误!这是 npm 本身的错误。请在以下位置报告此错误: npm 错误! https://npm.community

    然后我使用以下命令全局删除了 create-react-app sudo npm uninstall -g create-react-app

    然后

    npx create-react-app my-app --template typescript 一切正常

    参考他的指南enter link description here

    【讨论】:

      【解决方案3】:

      为我工作,您是否先尝试 npm uninstall -g create-react-app?这当然会全局卸载 create-react-app

      Ading Typescript

      【讨论】:

        猜你喜欢
        • 2018-01-11
        • 2020-12-23
        • 1970-01-01
        • 2020-04-04
        • 2023-04-01
        • 2019-11-29
        • 1970-01-01
        • 2021-01-11
        • 1970-01-01
        相关资源
        最近更新 更多