vue3+ts import引用报错Could not find a declaration file for module ‘three-obj-mtl-loader‘.

时间:2025-02-17 20:12:19

vue3+ts import引用报错记录及解决方式

  • 报错描述
    • 问题分析
    • 解决方式一
    • 解决方式二

报错描述

TS7016: Could not find a declaration file for module 'three-obj-mtl-loader'. 'D:/xx/xx/node_modules/three-obj-mtl-loader/' implicitly has an 'any' type.
  Try `npm i --save-dev @types/three-obj-mtl-loader` if it exists or add a new declaration (.d.ts) file containing `declare module 'three-obj-mtl-loader';`
  • 1
  • 2

问题分析

引用的文件可能不是.ts文件而是.js文件。

解决方式一

npm install @types/vue-xxx
  • 1

如果执行报错,请用解决方式二

解决方式二

找到目录下的文件,在最下面添加语句

declare module 'xxx' //xxx为 你需要引入但是报错的文件名,例如我的是 declare module 'three-obj-mtl-loader'
  • 1