Skip to content

babel-loader complains about syntax errors in code that should be removed #31

@jmanj78

Description

@jmanj78

I have a .js file with an entry that looks like this:

{
  text: 'link text',
  /// #if CONDITION
  url: 'url/if/true'
  /// #else 
  url: 'url/if/false
  /// #endif
}

I have tried setting up my webpack.config.js rules in a couple of different ways, neither of which is currently working:

webpackConfig.rules version 1

[
  { test: /\.(js|jsx)$/,
    use: [ 'babel-loader' ],
    exclude: /node_modules/ },
  ...
  { test: /\.(js|jsx)$/,
    use: [{ loader: 'ifdef-loader', options: { CONDITION: false } } ],
    exclude: /node_modules/ }
];

webpackConfig.rules version 2

[
  { test: /\.(js|jsx)$/,
    use: [ 'babel-loader',  { loader: 'ifdef-loader', options: { CONDITION: false } } ],
    exclude: /node_modules/ },
  ...
];

What happens is the babel-loader complains about a missing comma on the url: 'url/if/true' line, when that line (or the other one, depending on the condition) should not even be getting to the babel-loader, if my understanding of loaders is correct.

exact errors look like this:
ERROR in SyntaxError: path\to\folder \file.js: Unexpected token, expected "," (linenumber)

I can see that the ifdef-loader appears to be getting applied correctly if I turn on verbose, but the babel-loader still fails after that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions