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.

Bug: eslint cant load esm plugin

See original GitHub issue

Environment

Node version: npm version: 16.15.0 Local ESLint version: 8.21.0 Global ESLint version: - Operating System: Ubuntu

What parser are you using?

Default (Espree)

What did you do?

Trying to load an esm plugin with new ESLint and I can’t get it to work. Below should work according to documentation here.

Minimal Example
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import { ESLint } from "eslint";
import bf from '@blackflux/eslint-plugin-rules';
import json from "eslint-plugin-json";
import mocha from "eslint-plugin-mocha";

const eslint = new ESLint({
  cwd: dirname(fileURLToPath(import.meta.url)),
  fix: false,
  baseConfig: {
    root: true,
    extends: [
      'airbnb-base',
      'plugin:mocha/recommended',
      'plugin:markdown/recommended'
    ],
    rules: {
      '@blackflux/rules/c8-prevent-ignore': 1
    },
    env: {
      es6: true,
      node: true,
      mocha: true
    },
    globals: {},
    parser: '@babel/eslint-parser',
    parserOptions: {
      requireConfigFile: false
    },
    plugins: [
      { id: '@blackflux/rules', definition: bf }
    ]
  },
  // we use glob on passed in files, due to https://github.com/eslint/eslint/issues/5623
  ignore: false,
  reportUnusedDisableDirectives: 'error'
});

const results = await eslint.lintFiles([
  fileURLToPath(import.meta.url)
]);

But I’m getting The "path" argument must be of type string. Received an instance of Object

What did you expect to happen?

Eslint should load the plugin

What actually happened?

Eslint can’t load the plugin

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
simlucommented, Aug 13, 2022

No, this comment clarifies that you can’t. #15453 (comment)

I was talking about the comment after the one you linked. The last one in the ticket! It details that you can when using eslint programmatically

1reaction
ljharbcommented, Aug 13, 2022

This isn’t a bug; eslint uses require, and you can’t require ESM. Additionally, ESM is async, and eslint plugins/configs must be sync.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Request: Support ESM plugins · Issue #15453 · eslint ...
I would like to see ESLint support the eslint-plugin for ESM. This will allow us to import Pure ESM packages from eslint-plugin with...
Read more >
ESLint - Error: Must use import to load ES Module
I think the problem is that you are trying to use the deprecated babel-eslint parser, last updated a year ago, which looks like...
Read more >
Getting Started with ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
[eslint] failed to load plugin 'prettier' declared in '.eslintrc.js'
[Error] Failed to load plugin 'prettier' declared in '.eslintrc.js': Cannot find module 'eslint-plugin-prettier' Require stack ...
Read more >
Using ES Modules (ESM) in Node.js: A Practical Guide (Part 3)
ESLint for linting, including the Node ESLint plugin ... (February 2021) has a bug where it thinks Node.js doesn't support await import(.
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