vue3 main.ts文件中引入js文件

提示无法找到模块的申明文件
在这里插入图片描述
解决步骤:

  1. 在tsconfig.json文件中加入一个参数:allowJS
复制代码
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowJs": true,  //编译时允许有js
    "allowSyntheticDefaultImports": true,  //允许引入没有默认导出的模块
 }
复制代码
  1. include中加入js
  "include": [
    "src/**/*.ts",
    "src/**/*.js",//添加路径支持js
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],

此时tsconfig.json会出现一个报错

 

 需要在tsconfig.json文件中加入一个新的参数:outDir 即可

    "allowJs": true, //允许有js
    "allowSyntheticDefaultImports": true, //允许引用没有默认导出的模块
    "outDir": "./",  //将输出结构重定向到目录

 

posted @   爵岚  阅读(2959)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示