Webpack Karma cannot resolve local import -
i using webpack both app , tests (using https://github.com/webpack/karma-webpack it). app in typescript , tests in babel.
importing standalone module in tests works (using import { cleanhtml, fromhtml, tohtml } "../../app/utils/text.ts";, ie need mention .ts extension otherwise fails).
when try import react component imports component in file, following error: module not found: error: cannot resolve 'file' or 'directory' ./blocks/paragraph.
the tree of directory looks like:
src/ app/ components/ blocks/ paragraph.ts main.ts tests/ components/ main_tests.js utils/ and main.ts imports paragraph.ts import { paragraphblockcomponent } "./blocks/paragraph";
normal compilation works not tests. here karma config:
var path = require('path'); module.exports = function (config) { config.set({ basepath: 'src', singlerun: true, frameworks: ['mocha', 'chai'], reporters: ['dots'], browsers: ['firefox'], files: [ 'tests/index.js' ], preprocessors: { 'tests/index.js': ['webpack'] }, webpack: { noinfo: true, module: { loaders: [ { test: /\.ts$/, loaders: ['awesome-typescript-loader'] }, { test: /\_tests.js$/, loaders: ['babel-loader'] } ] } }, webpackmiddleware: { noinfo: true, stats: { color: true, chunkmodules: false, modules: false } } }); }; did miss something?
adding following karma webpack config fixed me
resolve: { extensions: ['', '.js', '.ts'] },
Comments
Post a Comment