0

I'm trying to import a carousel into my project and no matter which one I use I get errors saying you may need an appropriate loader pointing at the carousels css file

  {
    test: /\.s?css$/,
    include: [/src/],
    use: ExtractTextPlugin.extract({
      fallback: 'style-loader',
      use: ['css-loader', 'postcss-loader', 'sass-loader'],
    }),
  },

I am doing this so surely this should cover it right?

can post more code but error coming from here: react-responsive-carousel/lib/styles/carousel.min.css:1

SyntaxError: Unexpected token .

1
  • Paste your package.json file Commented Apr 15, 2018 at 11:36

4 Answers 4

1

Try adding loader:'style!css!'

  {
    test: /\.s?css$/,
    include: [/src/],
    loader:'style!css!',
    use: ExtractTextPlugin.extract({
      fallback: 'style-loader',
      use: ['css-loader', 'postcss-loader', 'sass-loader'],
    }),
  },

Attempt 2

Try updating test to test: /\.css$/, (long shot)

  {
    test: /\.css$/,
    include: [/src/],
    loader:'style!css!',
    use: ExtractTextPlugin.extract({
      fallback: 'style-loader',
      use: ['css-loader', 'postcss-loader', 'sass-loader'],
    }),
  },

Attempt 3

Try setting loaders this way

loaders: ['style-loader', 'css-loader'],

or

loader: "style-loader!css-loader"
Sign up to request clarification or add additional context in comments.

3 Comments

made no difference unfortunately :(
ok, that was the only reference I saw to the error you made.... github.com/shama/letswritecode/issues/8
Added a couple other things to try
0

Do this if you want to add multiple loaders

Install the modules like this npm install --save-dev css-loader

{
    test: /\.css$/,
    exclude: /node_modules/,
    use: ExtractTextPlugin.extract({
       fallback: "style-loader",
       use: [
           {
              loader: 'css-loader'
           },
           {
              loader: 'postcss-loader'
           }
           // more loaders if you have any
           // Make sure you installed this loaders
        ]
    })
}

Give this a try any let me know if any issues.

Reference here

5 Comments

missing a comma between use objects
still same issue unfortunately :(. it's still pointing at the first line of the css file inside the node module
Make sure the modules are installed
On which line you are getting this error @TheWalrus SyntaxError: Unexpected token .?
@RaajNadar here: workspace/project/node_modules/react-responsive-carousel/lib/styles/carousel.min.css:1
0

Make sure you updated your include to include /node_mobuldes

Also if that doesn't work try separating your css and sass loader.

{
  test: /\.css$/,
  include: [/node_modules/, /src/],
  use: ExtractTextPlugin.extract({
    fallback: 'style-loader',
    use: ['css-loader', 'postcss-loader', 'sass-loader'],
  }),
},
{
  test: /\.scss$/,
  include: [/src/],
  use: ExtractTextPlugin.extract({
    fallback: 'style-loader',
    use: ['css-loader', 'postcss-loader', 'sass-loader'],
  }),
},

Comments

0

Try importing the carousel css in your css/scss file like this

@import "~react-responsive-carousel/lib/styles/carousel.min.css"; 

then in your webpack file try this setting

  {
    test: /\.css$/,
    exclude: /node_modules/,
    use: ExtractTextPlugin.extract({
      fallback: 'style-loader',
      use: 'css-loader!postcss-loader',
    }),
  };
  {
    test: /\.scss$/,
    exclude: /node_modules/,
    use: ExtractTextPlugin.extract({
      fallback: 'style-loader',
      use: 'css-loader!postcss-loader!sass-loader',
    }),
  };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.