Search code examples
csstypescriptwebpackcss-loaderextract-text-plugin

Webpack - Import Less from TypeScript fails (css-loader)


I'm trying to build a test project with TypeScript via Webpack. Have just index.ts file and base.less (or base.css) file imported in index.ts and it fails with errors on css-loader. Without imported LESS (CSS) file in a .ts file all working good.

I have got another big project with JS only (no TypeScript) and it working good with the same webpack.config file (babel instead of ts loader).

[email protected]

All needed loaders are installed.

webpack.config.js and Bitbucket link to the test project

ERROR in ./~/css-loader/lib/css-base.js Module build failed: Error: Final loader didn't return a Buffer or String

enter image description here

enter image description here


Solution

  • You have a wrong RegExp rule for TypeScript loader in your webpack.config.js. You need this:

    `test: /(.ts|.tsx)$/`
    

    but you have this:

    `test: /(.ts|.tsx)?/`
    

    Which says: load as TypeScript file no matter what.