Why is my webpack trying to load .js files when co

2019-05-23 22:17发布

I'm trying to use blueprintjs so I followed the tutorial with this line:

main.sass

@import "~@blueprintjs/core";

However my webpack-dev-server gives me this error log:

ERROR in ./node_modules/css-loader?{"minimize":false}!./node_modules/postcss-loader/lib?{"sourceMap":true}!./node_modules/resolve-url-loader!./node_modules/sass-loader/lib/loader.js?{"sourceMap":true}!./app/javascript/packs/main.sass
Module build failed:
 */
  ^
      Invalid CSS after " */": expected 1 selector or at-rule, was '"use strict";'
      in <redacted>/node_modules/@blueprintjs/core/dist/index.js (line 6, column 4)
webpack: Failed to compile.

So I'm confused why it's trying to parse an index.js file as sass into css!

Looking at ./config/webpack/loaders/sass.js, which I haven't touched:

const ExtractTextPlugin = require('extract-text-webpack-plugin')
const { env } = require('../configuration.js')

module.exports = {
  test: /\.(scss|sass|css)$/i,
  use: ExtractTextPlugin.extract({
    fallback: 'style-loader',
    use: [
      { loader: 'css-loader', options: { minimize: env.NODE_ENV === 'production' } },
      { loader: 'postcss-loader', options: { sourceMap: true } },
      'resolve-url-loader',
      { loader: 'sass-loader', options: { sourceMap: true } }
    ]
  })
}

I only see it trying to read sass, scss and css files. Any ideas what I'm missing or should check?

2条回答
女痞
2楼-- · 2019-05-23 22:25

You are receiving an error because in you main.sass file you are importing a JS module. ~@blueprintjs/core resolves to node_modules/@blueprintjs/core/dist/index.js and thus you are getting JS mixed in the process.

You should see what files the blueprintjs/core/dist folder contains and only import sass/scss/css files to make your build.

查看更多
孤傲高冷的网名
3楼-- · 2019-05-23 22:35

you just need to add the code below on your App.css file

@import "~@blueprintjs/core/dist/blueprint.css";

查看更多
登录 后发表回答