【问题标题】:Karma - Module not found: Error: Cannot resolve module 'scss'Karma - 未找到模块:错误:无法解析模块“scss”
【发布时间】:2016-09-09 21:47:29
【问题描述】:

我有一个要为其编写测试的模块。我使用 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 is not found 的错误

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 文件并运行我的测试?

【问题讨论】:

    标签: javascript angularjs webpack karma-runner


    【解决方案1】:

    问题是一个错字:

    scss 应该是sass

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

    【讨论】:

      猜你喜欢
      • 2017-03-22
      • 1970-01-01
      • 1970-01-01
      • 2021-07-04
      • 2017-04-18
      • 2019-12-26
      • 2019-01-31
      • 1970-01-01
      • 2022-11-10
      相关资源
      最近更新 更多