0

I boiled my problem down to a minimum test. I have an App.js file which contains a bit of jsx and which is to be compiled to ./bundle.js:

// App.js
module.exports = () => <div/>

My webpack config seems quite standard with

module.exports = {
    entry: './App.js',
    output: {
        filename: './bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                loader: 'babel-loader',
                //include: ['./includes'],  // <- Problem line
                query: {
                    plugins: [
                        ['transform-react-jsx']
                    ]
                }
            }
        ]
    }
}

This works and compiles correctly only if the line with include is removed. If I enable that line then I get the error

Module parse failed: ./App.js Unexpected token (1:23)
You may need an appropriate loader to handle this file type.
| module.exports = () => <div/>

I have no idea why it would fail when I specify an include for the loader, even include: [] fails with that same error.

Does anyone have an idea?

Michel H.
  • 301
  • 1
  • 11

1 Answers1

1

include is just like test.

  • include: [] means "include nothing"`
  • include: ["./include"] means "only include files in the include directory"

so either if those will exclude ./App.js.

loganfsmyth
  • 156,129
  • 30
  • 331
  • 251
  • Thank you, this absolutely makes sense. However, what would `include` look like? I get the same error even with `include: ['.', './App.js', './includes'],` – Michel H. Feb 01 '18 at 13:16
  • That would be because `App.js` is in `__dirname`. Why are you trying to add this in the first place? – loganfsmyth Feb 01 '18 at 16:55
  • I would have expected relative paths to work as well. I am working on making a client-only web app universal and am experimenting with this to inject client-only code in a clean way. – Michel H. Feb 02 '18 at 19:54