我正在尝试在Webpack配置中支持* .scss文件,但是在运行webpack build命令时,始终出现以下错误:
ERROR in ./~/css-loader!./~/sass-loader!./app/styles.scss
Module build failed: TypeError: Cannot read property 'sections' of null
at new SourceMapConsumer (/Users/sean/Development/playground/webpack.sass.test/node_modules/css-loader/node_modules/postcss/node_modules/source-map/lib/source-map/source-map-consumer.js:23:21)
at PreviousMap.consumer (/Users/sean/Development/playground/webpack.sass.test/node_modules/css-loader/node_modules/postcss/lib/previous-map.js:37:34)
at new Input (/Users/sean/Development/playground/webpack.sass.test/node_modules/css-loader/node_modules/postcss/lib/input.js:42:28)
at parse (/Users/sean/Development/playground/webpack.sass.test/node_modules/css-loader/node_modules/postcss/lib/parse.js:17:17)
at new LazyResult (/Users/sean/Development/playground/webpack.sass.test/node_modules/css-loader/node_modules/postcss/lib/lazy-result.js:54:47)
at Processor.process (/Users/sean/Development/playground/webpack.sass.test/node_modules/css-loader/node_modules/postcss/lib/processor.js:30:16)
at processCss (/Users/sean/Development/playground/webpack.sass.test/node_modules/css-loader/lib/processCss.js:168:24)
at Object.module.exports (/Users/sean/Development/playground/webpack.sass.test/node_modules/css-loader/lib/loader.js:21:15)
@ ./app/styles.scss 4:14-117
我无法为自己的生活弄清楚原因。这是一个非常基本的设置。
我创建了一个保管箱共享,其中最少的说明了这一点:https : //www.dropbox.com/s/quobq29ngr38mhx/webpack.sass.test.zip?dl=0
解压缩然后运行:
npm install
webpack
这是我的webpack.config.js文件:
var path = require('path')
var webpack = require('webpack')
module.exports = {
devtool: 'eval',
entry: [
'./app'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js',
publicPath: '/dist/'
},
plugins: [
new webpack.NoErrorsPlugin()
],
resolve: {
extensions: ['', '.js']
},
module: {
loaders: [{
test: /\.scss$/,
loader: 'style-loader!css-loader!sass-loader'
}]
}
}
还有index.js入口文件:
require('./styles.scss');
alert('foo bar baz');
以及styles.scss文件:
body {
background-color: #000;
}
它似乎遵循sass-loader文档站点的建议,但我无法使其运行。
:(
有关我的环境的信息:
node - 0.12.4
npm - 2.10.1
os - OS X Yosemite
在遇到相同的问题后,我发现了这一点:https : //github.com/webpack/css-loader/issues/84
显然,目前的解决方案是使用以下命令手动修改/node_modules/css-loader/lib/loader.js的第17-19行
这为我解决了问题。