• vite+react+typescript 遇到的问题


    1.找不到模块“vite”。你的意思是要将 “moduleResolution” 选项设置为 “node”,还是要将别名添加到 “paths” 选项中

    tsconfig.json 中 compilerOptions:{“moduleResolution”: node}

    2.未知的编译器选项“allowImportingTsExtensions”
    该选项用于控制是否允许在 import 语句中导入 .ts 文件扩展名,它的取值可以是 true 或 false。但是,从 TypeScript 3.8 开始,这个选项已经被废弃了

    删除tsconfig文件中的"allowImportingTsExtensions": true,

    3.vite.config.ts配置文件中__dirname解析不到
    npm install @types/node --save-dev

    4.类型“JSX.IntrinsicElements”上不存在属性“div”。

    tsconfig.json 中 compilerOptions:{“moduleResolution”: node}

    5. ReferenceError: React is not defined
    方案一
    在报错的文件引入 React
    import React,{ useState } from ‘react’ 作者:doubleyong https://www.bilibili.com/read/cv19649507/ 出处:bilibili

    方案二
    如果这样配置了,
    react({
    babel: {
    plugins: [“@babel/plugin-transform-react-jsx”],//解决编译不成功jsx问题
    },
    })
    去掉{
    babel: {
    plugins: [“@babel/plugin-transform-react-jsx”],//解决编译不成功jsx问题
    },
    }
    方案三
    直接升级到最新版本的vscode软件。

    6. build An import path can only end with a ‘.tsx’ extension when ‘allowImportingTsExtensions’ is enabled.
    方案一
    不写文件后缀:是因为新版本在导入模块时,可以不添加.tsx扩展名
    方案二
    tsconfig.json 中 compilerOptions:{“allowImportingTsExtensions”: true}
    注: 会报错未知的编译器选项“allowImportingTsExtensions”。只能忽视

  • 相关阅读:
    IDEA 中贼好用的插件-开发利器
    Lazada最新招商政策,新商家入驻享90天返佣扶持!
    C++回顾录04-构造函数
    Docker容器故障排查与解决方案
    dubbo没有找到生产者
    LLM推理的极限速度
    Excel 语法
    SpringMvc内置的九大组件
    【牛客网】:链表的回文结构(提升)
    vue插槽(匿名插槽,具名插槽,有作用域的插槽 )
  • 原文地址:https://blog.csdn.net/qq_43383334/article/details/134464415