1

In my react.js app I am trying to use an external module (React Toastify) using the following statement:

import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

Unfortunately this throws the following error:

Uncaught Error: Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
> .Toastify__toast-container {
|   z-index: 9999;

I guess it has something to do with webpack, here are my settings in webpack.config.js:

    output: {
  filename: '[name].js',
  path: path.resolve(__dirname, 'assets'),
},

devtool: production ? '' : 'source-map',

resolve: {
  extensions: [".js", ".jsx", ".json"],
},


module: {
  rules: [
    {
     test: /\.jsx?$/,


      exclude: /node_modules/,



      loader: 'babel-loader',
    },
  ],
},

};

I am not sure how this can be fixed, any advice appreciated.

2
  • 1
    You need to add css loader to webpack plugins Commented Mar 30, 2019 at 16:04
  • @fastAsTortoise Ah, of course - I was using a boilerplate where it wasnt declared. Now it works, thanks a lot! Commented Mar 30, 2019 at 16:15

1 Answer 1

2

In your webpack config file you have add the css loader test:

module: {
  rules: [
    {
      test: /\.jsx?$/,
      exclude: /node_modules/,
      loader: 'babel-loader',
    }, {
      test: /\.css$/,
      use: ['style-loader', 'css-loader'],
    },
  ],
},

And don't forget to install it with npm i -D css-loader.

More info here: https://github.com/webpack-contrib/css-loader

Sign up to request clarification or add additional context in comments.

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.