happypack icon indicating copy to clipboard operation
happypack copied to clipboard

babel plugins not recognized?

Open thim22 opened this issue 8 years ago • 4 comments

Using webpack v2 (2.2.1) + happypack 3.0.2 gives me a lot of these types of errors:

Module parse failed: /app/node_modules/happypack/loader.js?id=hp-babel!/somefile.js Unexpected token (107:19) You may need an appropriate loader to handle this file type.`

Without happypack, the build runs just fine which makes me suspect the .babelrc config which includes several plugins is not being used.

Here's some relevant config:

webpack.config.json

...
  plugins: 
    new HappyPack({
      // loaders is the only required parameter:
      id: 'hp-babel',
      loaders: ['babel-loader'],
      verbose: true,
      debug: true
    }),
...
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        include: APP_PATH,
        use: [
          {
            loader: 'happypack/loader?id=pack/loader?id=hp-babel'
          }
        ]
      },
...

.babelrc

 {
    "presets": [
      [
      "es2015",
        {
          "modules": false
        }
      ],
      "stage-0",
      "react"
    ],
    "plugins": [
      "transform-decorators-legacy",
      "transform-runtime",
      "babel-plugin-transform-class-properties",
      "transform-object-rest-spread"
    ],
    "env": {
      "production": {
        "plugins": [
          "transform-react-remove-prop-types"
        ]
      }
    }
}

thim22 avatar Feb 21 '17 03:02 thim22

Hey, can you please try out the master branch and see if it fixes the issue? It seems similar to #132.

Edit: in fact, version 3.0.3 on NPM now should incorporate the mentioned fix. You can try that instead of master.

amireh avatar Feb 21 '17 04:02 amireh

I can confirm 3.0.3 fixes my issue, thanks man!

thim22 avatar Feb 21 '17 07:02 thim22

I'm using HappyPack v4.0.1 with webpack v3.8.1, babel-Loader v7.1.2, babel-preset-env v1.6.1 and babel-plugin-transform-object-rest-spread and I'm seeing the exact same problem.

I'm compiling for node and trying to use object-rest-spread. HappyPack seems to ignore my babel plugins if I include them in the webpack config OR in .babelrc. I get errors about using the ... operator.

If I remove happypack and just use a regular webpack loader it works fine.

darkadept avatar Mar 20 '18 20:03 darkadept

Do you know if it's reading the .babelrc file at all? I assume it also includes presets along with the plugins, is it just the plugins that aren't recognized?

  • If it's the entire file not being read, try setting the webpack "context" configuration parameter and see if that helps. It should point to your source code's root folder (or wherever the top-most .babelrc file lives in.)
  • Try also specifying the .babelrc file directly in your loader options just to troubleshoot what's going on. You can do it with something like:
new HappyPack({
  id: 'hp-babel',
  loaders: [{
    loader: 'babel-loader',
    options: { babelrc: path.resolve(__dirname, '.babelrc') } // or wherever
  }],
  verbose: true,
  debug: true
}),

I've not seen such an issue with .babelrc so it's likely we're missing something else in the config.

amireh avatar Mar 20 '18 20:03 amireh