react-chat-window icon indicating copy to clipboard operation
react-chat-window copied to clipboard

SVG loading error

Open thiagocoelho opened this issue 6 years ago • 5 comments

I'm trying to use the Launcher but in first run I got this:

ERROR in ./node_modules/react-chat-window/es/assets/chat-icon.svg Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type. | <svg xmlns="http://www.w3.org/2000/svg"

I need to install anything besides react-chat-window?

thiagocoelho avatar Mar 09 '18 22:03 thiagocoelho

Hi @thiagocoelho, If you are still experiencing this issue, could you provide more details to help us understand? (for example, what you mean by "trying to use the Launcher", what steps you took leading up to this error, etc) The cause of the problem is not immediately apparent to me, though perhaps @dharness might have more of an idea.

heatherbooker avatar Aug 08 '18 03:08 heatherbooker

So I am running into a similar issue in my Next.JS project which I have a suspicion he may be using as well.

I am including the Launcher using this import { Launcher } from 'react-chat-window'

which triggers the exact same error as @thiagocoelho.

Looking into Next a little more I think it is related to this topic: https://github.com/zeit/next.js/issues/79 where Next needs a folder defined to serve up images.

Tried to tinker around with a solution but couldn't quite figure it out yet...

JeffLoo-ong avatar Dec 23 '18 01:12 JeffLoo-ong

It sounds like we should embed the svg manually in the jsx instead of importing it - if anyone has time to make that change it'd be great

dharness avatar Dec 23 '18 01:12 dharness

I am hopeful that using webpack with the appropriate file-loader will fix if this sort of thing pops up again, in #128:

      test: /\.(png|svg|jpg|gif|mp3)$/,
      use: [
        'file-loader'
      ]

heatherbooker avatar Jul 19 '19 20:07 heatherbooker

define SRC like this:

var path = require('path');
var SRC = path.resolve(__dirname, 'src/main/js');

And use file-loader for mp3 (module -> rules):

{
    test: /\.mp3$/,
    include: SRC,
    loader: 'file-loader'
}

or use image-webpack-loader for load images:

{
        test: /\.(gif|png|jpe?g|svg)$/i,
        use: [
          'file-loader',
          {
            loader: 'image-webpack-loader',
            options: {
              bypassOnDebug: true, // [email protected]
              disable: true, // [email protected] and newer
            },
          },
        ]}

For example, this is my webpack.config.js:

const path = require('path');
const SRC = path.resolve(__dirname, 'node_modules');

module.exports = {
  entry: './jsx/App.jsx',
  mode: "development",
  output: {
    path:
        '/java/helios-backend/src/main/resources/static/js'
        // __dirname + '/js/'
    ,
    filename: 'bundle.js'
  },
  devtool: '#sourcemap',
  stats: {
   colors: true,
   reasons: true
  },
  module: {
    rules: [
      { test: /\.css$/, loader: 'style-loader!css-loader' },
      {
        test: /\.jsx?$/,
        exclude: /(node_modules)/,
        loaders: ['babel-loader']
      },
      {
        test: /\.(gif|png|jpe?g|svg)$/i,
        use: [
          'file-loader',
          {
            loader: 'image-webpack-loader',
            options: {
              bypassOnDebug: true,
              disable: true, 
            },
          },
        ]},
      {
        test: /\.mp3$/,
        include: SRC,
        loader: 'file-loader'
      }

    ]
  }
};

And do not forget to install the file-loader before:

npm install file-loader --save-dev

I'm not sure if this is the best solution, but it works :)

AppLoidx avatar Aug 31 '19 06:08 AppLoidx