因果报应-找不到模块:错误:无法解析模块'scs'

Karma - Module not found: Error: Cannot resolve module 'scss'

本文关键字:模块 scs 找不到 错误 因果报应      更新时间:2023-09-26

我有一个模块,我想为它编写一个测试。我使用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文件并运行测试?

问题是打字错误:

scss应该是sass

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