首页 > 解决方案 > win10纱线找不到打字稿

问题描述

我有一个 git repo,我应该使用 command 启动它react-scripts start。当我运行这个命令时,我得到这个响应说 typescript 找不到:

react-scripts start
It looks like you're trying to use TypeScript but do not have typescript installed.
Please install typescript by running npm install typescript.
If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files).

我尝试使用 npm i typescript、npm i -g typescript、yarn add typescript、yarn global add typescript 和“choco install typescript”在命令提示符下安装 typescript。

我可以运行打字稿文件,但是如果我尝试启动我的程序,我仍然会收到错误消息,说我没有安装打字稿。

如果我只是tsc在命令提示符或 powershell 中运行,我会收到一些我试图解决但没有运气的错误警报:

 tsc
src/App.tsx:12:5 - error TS2307: Cannot find module 'react/jsx-runtime' or its corresponding type declarations.

 12     <UserAccountContext.Provider value={guestAccount}>
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 13       <div className="App container">
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
 24       </div>
    ~~~~~~~~~~~~
 25     </UserAccountContext.Provider>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/App.tsx:13:7 - error TS2339: Property 'div' does not exist on type 'JSX.IntrinsicElements'.

13       <div className="App container">
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/App.tsx:15:9 - error TS2339: Property 'div' does not exist on type 'JSX.IntrinsicElements'.

有什么方法可以确保安装了打字稿?我尝试在 powershell 和命令提示符下运行安装命令。

标签: javascriptnode.jsreactjstypescript

解决方案


您可以使用yarn add typescript @types/node @types/react @types/react-dom @types/jestor简单地安装在您的项目中npm install --save typescript @types/node @types/react @types/react-dom @types/jest

如果您对脚本有问题,也许更新它们会解决它,您可以尝试以下命令:npm install react-scripts@latest

有关更多信息,您可以查看以下链接:创建 React AppTypescript Docs

您还可以检查对 TS 具有原生支持的框架,例如NextGatsby


推荐阅读