typescript can't find module less
Asked Answered
S

2

16

enter image description here

I use react and webpack to build web SPA but, typescript can't find resolve the less file

enter image description here

work file like this ⬆️

Seismism answered 30/9, 2017 at 9:5 Comment(4)
Please share some of your code so we can help.Sudorific
Please show more context (directory structure with file names, etc).Philodendron
Please don’t post images of code, error messages, or other textual data.Christlike
you can refer this as well How to import a scss file into a typescript fileOverdose
G
46

Just create a new declaration file (externals.d.ts) with declare module '*.less'.

Edit If you are using css-modules, you can define these types to match the return value:

declare module '*.less' {
  const resource: {[key: string]: string};
  export = resource;
}

Add that file to the includes array of your tsconfig.json file.

// tsconfig.json
{
   compilerOptions: {...}
   includes: [
      './path/to/the/new/file/externals.d.ts'
   ]
}
Granny answered 30/9, 2017 at 9:12 Comment(1)
Killed couple of hours, trying to solve this %) Thank you for help!Baal
C
14

Add to src/react-app-env.d.ts or declaration.d.ts

declare module '*.less';

or if you use css-modules

declare module '*.module.less' {
  const classes: { [className: string]: string };
  export default classes;
}
Camargo answered 26/5, 2020 at 10:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.