1

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).

Webpack@2.2.0

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

Max
  • 404
  • 2
  • 17
  • 39

1 Answers1

1

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.

GProst
  • 9,229
  • 3
  • 25
  • 47
  • I fixed it today but have not push yet. But ts scripts work fine. Webpack gives an error only when I write "import './less/base.less'. I found (in webpack2 documentation) that I need to add .d.ts file with declare '*.less' (and CSS) but still it did not help, got the same error. Just 10 minutes and I will push my updated files. Now there is a JS file with imported less that works and TS file with only TS code without importing styles that also works. But if I move import from styles.js to index.ts I got an error above. – Max Jan 26 '17 at 10:47
  • webpack gives an error on `import 'base.less'` because it thinks that it is a `.ts` file. Fix the RegExp rule as I suggested and everything will be OK – GProst Jan 26 '17 at 10:57
  • Yes! It works... Unbelievable. I fix ? with $ but got another error in this Regexp. Thanks!!! – Max Jan 26 '17 at 11:03