2016-05-13 173 views
1

我有一個模塊,我想寫一個測試。我使用webpack進行編譯,因爲我在ES6中編寫它。Karma - 模塊未找到:錯誤:無法解析模塊'scss'

文件(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

問題是一個錯字:

scss應該已經sass

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