question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESLint errors for code injected by Babel

See original GitHub issue

I’m using Babel with preset-env for IE support (sad, I know), and I’m getting these errors:

/.../TestWorker.js
  4:3   warning  Unexpected var, use let or const instead  no-var
  5:29  warning  Unexpected function expression            prefer-arrow-callback
  8:7   warning  Expected property shorthand               object-shorthand
 10:12  warning  Unexpected function expression            prefer-arrow-callback
 13:7   warning  Expected property shorthand               object-shorthand

The warnings seem to be about code that would be injected by Babel, but ESLint runs with enforce: pre, so looks like double processing. This happens only for the worker the rest of the code is built correctly.

Here’s the (simplified) code for my worker:

import process from './process';

self.onmessage = ({data}) =>
	process(data)
		.then(result => postMessage({type: 'success', result}))
		.catch(error => postMessage({type: 'error', error}));

This could be related to the problem reported in #86.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
jcestibarizcommented, Dec 22, 2020

@dohun-toss I had not noticed that eslint-loader was deprecated. Using eslint-webpack-plugin fixed the problem, thank you!

0reactions
dohun-tosscommented, Dec 22, 2020
module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: ['babel-loader', 'eslint-loader'], // without enforce pre, you can use lint first
      },
    ],
  },
  // ...
};

but, eslint-loader is deprecated. how about trying to migrate to eslint-webpack-plugin?

Before:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'eslint-loader',
        options: {
          // eslint options (if necessary)
        },
      },
    ],
  },
  // ...
};

After:

const ESLintPlugin = require('eslint-webpack-plugin');

module.exports = {
  // ...
  plugins: [new ESLintPlugin(options)],
  // ...
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Build initially fails when using both babel and eslint but ...
Build fails on first attempt, succeeds on the second, with no code changes. Any changes to main.js (even trivial ones such as adding...
Read more >
Eslint and Babel parser throwing errors in React
Having some strange behaviour when trying to configure ESlint(global install) and babel: Editor(VSCode) showing error on top most import:.
Read more >
Avoid Common JavaScript Errors with ESLint
ESLint uses static analysis to check that your code adheres to a list of rules to help you avoid some specific runtime errors....
Read more >
ESLint: The guardian of code conventions ⚔️
ESLint is a tool that allows us to maintain code quality and enforce code conventions. ESLint is a static code evaluator. Basically, it...
Read more >
Find and fix problems in your JavaScript code - ESLint ...
The pluggable linting utility for JavaScript and JSX​​ ESLint is an open source project that helps you find and fix problems with your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found