Typescript Compiler "cannot Find Module" When Using Webpack Require For Css/image Assets
I am writing vanilla Javascript but using the Typescript compiler's checkJs option to do type checking in VSCode. I have Webpack set up to load various asset types (CSS, images, e
Solution 1:
Requiring non JS or TS resources is currently not supported by the TypeScript server which powers VS Code's JavaScript and TypeScript intellisense. Here's the issue tracking this: https://github.com/Microsoft/TypeScript/issues/15146
As a workaround, try creating a d.ts
file in your project with the content:
declaremodule'*.css' { exportdefault''asstring; }
declaremodule'*.png' { exportdefault''asstring; }
You can also suppress individual errors by adding // @ts-ignore
before the require:
// @ts-ignorevar img = require("../img/image.png");
Post a Comment for "Typescript Compiler "cannot Find Module" When Using Webpack Require For Css/image Assets"