Karma - 找不到模块:错误:无法解析模块' scss'

时间:2016-05-13 15:51:22

标签: javascript angularjs webpack karma-runner

我有一个我想为其编写测试的模块。我使用webpack进行转换,因为我在ES6中编写它。

文件(app.js)的开头如下:

import template from './app.html'; // pulls in the template for this component
import './app.scss'; // pulls in the styles for this component

但是当我运行测试时,我收到一个错误,即找不到app.scss

ERROR in ./src/app.js
Module not found: Error: Cannot resolve module 'scss' in /Users/.../src
 @ ./src/app.js 11:0-21
13 05 2016 10:38:52.276:INFO [..browserinfo..]: Connected on socket /#KYFiNbOR-7lqgc9qAAAA with id 63011795
(browser) ERROR
  Uncaught Error: Cannot find module "./app.scss"
  at /Users/.../spec.bundle.js:34081 <- webpack:///src/app.js:4:0

Finished in 0.241 secs / 0 s

测试从这样开始:

import angular from 'angular';
import header from './app.js'; // error occurs here cause .scss file is not recognized

describe('my module', () => {
  let $rootScope, makeController;
  // testing stuff
});

我的karma.conf.js文件包括:

webpack: {
  devtool: 'inline-source-map',
  module: {
    loaders: [
      { test: /\.js/, exclude: [/app\/lib/, /node_modules/], loader: 'babel' },
      { test: /\.html/, loader: 'raw' },
      { test: /\.scss/, loader: 'style!css!scss' },
      { test: /\.css$/, loader: 'style!css' }
    ]
  }
}

如何让karma / webpack正确读取scss文件并运行我的测试?

1 个答案:

答案 0 :(得分:1)

问题是错字:

scss应该是sass

webpack: {
  module: {
    loaders: [
      ...,
      { test: /\.scss/, loader: 'style!css!sass' },
      ...
    ]
  }
}