[Solved] TS Error: Could not find a declaration file for module

Some NPM packages have no problem using native JS, and some packages will report “could not find a declaration file for module” error after changing ts.

There are two ways to solve this problem

1. Download the @ type/error reporting package (some package developers may not upload their own. D.ts code to the NPM branch, then they will report an error saying that they can’t find this package, don’t worry about the next step)

2. The most direct, simple and effective solution: create a new shims-vue.d.ts file in the root directory of the project

//declare declaration declares an ambient module (i.e., a module declaration without internal implementation) 
declare module '*.vue' {
  import Vue from 'vue'
  export default Vue
}
 
 
declare module 'XX'
// xx is the name of the package that your package cannot find declared

The only thing to note is that after the first creation of the file with vscode, it should be restarted to see the effect, and then it will take effect. After the declaration is saved, the error will disappear immediately.

Read More: