获取错误:模块解析失败:...意外字符'#'

时间:2017-06-07 14:21:18

标签: javascript css reactjs webpack redux

我第一次使用webpack,想在我的react / redux应用程序中使用一些css。我按照指南,但似乎仍然有问题。你可以看到我收到上述错误。

文件夹结构如下所示:

.git
-node_modules
-public
 -bundle.js
 -index.html
-src
 -actions
 -components
 -reducers
 app.js
-style
 -style.css
.babelrc
.gitingore
package-lock.json
package.json
README.md
server.js
webpack.config.js

这是确切的错误:

Uncaught Error: Module parse failed: C:\Users\Amazo\projects\reduxApp\style\style.css Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
| #row1 {
|   margin-top: 15px;
| }

我将在下面发布我的webpack配置文件:

var path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
var HTMLWebpackPlugin = require('html-webpack-plugin');


module.exports = {
  entry: './src/app.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'public')
  },
  watch: true,
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude:/node_modules/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-1']
        }
      },
      {
        use: ['style-loader', 'css-loader'],
        test: /\.css$/
      }
    ]
  },
  resolve: {
    extensions: ['.js','.jsx']
  },
  plugins: [
    new HTMLWebpackPlugin({
      template: 'public/index.html';
    }),
    new ExtractTextPlugin('style.css')
  ]
};

1 个答案:

答案 0 :(得分:0)

.css添加到您的resolve

resolve: {
  extensions: ['.js','.jsx', '.css']
},

否则,webpack无法正确处理