javascript - Cannot find module error when using karma-webpack -
i have following karma.conf.js
file, have test file called example.spec.js
lives inside app/compontents/example/example.spec.js
trying import example.js file
import example 'app/components/example/example.jsx'; describe('example component', function() { });
but following error error: cannot find module "app/components/example/example.jsx"
have tried many different ideas, such ./example.jsx
, ./example
, components/example/example.jsx
each time same error.
var webpack = require('webpack'); module.exports = function(config) { config.set({ // milliseconds browsernoactivitytimeout: 40000, // frameworks use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['mocha', 'chai'], // list of files / patterns load in browser files: [ 'app/tests/setup.js', 'app/**/*.spec.js' ], // preprocess matching files before serving them browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { 'app/tests/setup.js': ['webpack', 'sourcemap'], 'app/**/*.spec.js': ['webpack', 'sourcemap'] }, webpack: { devtool: 'inline-source-map', cache: false, resolve: { extensions: ['', '.js', '.jsx'], modulesdirectories: ['node_modules', 'app'], fallback: __dirname }, module: { preloaders: [], loaders: [ { test: /\.(js|jsx)$/, loaders: ['babel-loader'], exclude: /node_modules/ }, ], plugins: [ new webpack.defineplugin({ 'process.env.node_env': json.stringify('test') }) ] } }, webpackmiddleware: { progress: false, stats: false, debug: false, noinfo: true, silent: true }, // test results reporter use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter reporters: ['dots'], // web server port port: 9876, // enable / disable colors in output (reporters , logs) colors: true, // level of logging // possible values: config.log_disable || config.log_error || config.log_warn || config.log_info || config.log_debug loglevel: config.log_info, // enable / disable watching file , executing tests whenever file changes autowatch: false, // start these browsers // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher browsers: ['phantomjs'], // continuous integration mode // if true, karma captures browsers, runs tests , exits singlerun: true, plugins: [ 'karma-mocha', 'karma-chai', 'karma-webpack', 'karma-sourcemap-loader', 'karma-phantomjs-launcher' ] }); };
if want use import that, you'll need set resolve.alias. demo:
resolve: { alias: { app: path.join(__dirname, 'app') } }
Comments
Post a Comment