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 ⬆️

palaѕн
  • 72,112
  • 17
  • 116
  • 136
pssgo
  • 211
  • 2
  • 3
  • 6

2 Answers2

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'
   ]
}
felixmosh
  • 32,615
  • 9
  • 69
  • 88
13

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;
}
Igor Sukharev
  • 2,467
  • 24
  • 21