javascript - 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 和命令提示符下运行安装命令。
解决方案
您可以使用yarn add typescript @types/node @types/react @types/react-dom @types/jest
or简单地安装在您的项目中npm install --save typescript @types/node @types/react @types/react-dom @types/jest
。
如果您对脚本有问题,也许更新它们会解决它,您可以尝试以下命令:npm install react-scripts@latest
有关更多信息,您可以查看以下链接:创建 React App和Typescript Docs
推荐阅读
- c# - ASP.Net Core 明确的两因素“记住我”偏好
- push-notification - 有没有办法使用 firebase-admin-sdk python 来安排 firebase 推送通知?
- python - 在修剪框上裁剪 pdf 并在 Python 中另存为 jpg?
- php - 用于操作“=”的排序规则 (utf8mb4_general_ci,IMPLICIT) 和 (utf8mb4_0900_ai_ci,IMPLICIT) 的非法混合
- javascript - 如何使用 LeafletJS 的图层组和图层控件将 GeoJSON 数据添加到图层
- npm - 无法在 node-red 中安装节点
- linq - LINQ 中的内部连接
- java - IntelliJ 无法识别 SLF4J
- sockets - http服务器整个线程池被recv阻塞
- delphi - 防止项目树显示delphi rtl单元