'Encountering errors while trying to import node modules in Vue 3 (I'm not using typescript)

I've installed KaTeX using the command npm install katex in my vue3 project.

However, when I try to import the katex module using the following code import katex from 'katex' inside my scripts section, vscode shows this error :

Could not find a declaration file for module 'katex'. 'c:/Users/User/Documents/vue/addsub/math/node_modules/katex/dist/katex.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/katex` if it exists or add a new declaration (.d.ts) file containing `declare module 'katex';`Vetur(7016)
Could not find a declaration file for module 'katex'. 'C:/Users/User/Documents/vue/addsub/math/node_modules/katex/dist/katex.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/katex` if it exists or add a new declaration (.d.ts) file containing `declare module 'katex';`ts(7016)

Can someone help me understand what is the issue ?



Solution 1:[1]

When a module is not yours - try to install types from @types:

npm install -D @types/module-name

If the above install errors - try changing import statements to require:

// import * as yourModuleName from 'module-name';
const yourModuleName = require('module-name');

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Guy Nachshon