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.

Allow for dynamic import() to be used in eslint config file

See original GitHub issue

The version of ESLint you are using.

ESLint-v7.8.1

The problem you want to solve.

Currently, while eslint understands the meaning of the .cjs extension, it is unable to load a config file that uses dinamic import() statements. It fails with an error:

TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.

This is caused by the dependency v8-compile-cache which patches the node internal Module.prototype._compile method in an insufficient fashion.

The purpouse of solving this is easier handeling of eslint configs for esm-users until config-file-simplification arrives (RFC). The Roadmap estimated the implementation to arrive in 5 months (6 months when the statement was made).

Your take on the correct solution to problem.

As the problem is caused by a dependency, there is no straight forward solution. I’ll file an issue in in the project after i’m done here. issue filed

NOTE: While debugging the issue, I found some things that are potential road-blocks for esm support (like the dependency import-fresh, which dispite the name is for loading cjs). I’ll be doing some more exploring and will post a proper report (propaby in the RFC repo) once i have some spare time.

Are you willing to submit a pull request to implement this change?

Potentially. I’ll check what exactly would need to have to change in v8-compile-cache and possibly make a PR there to solve the problem at the root. Besides that, it depends on what I find while examining the things mentioned in the note.

NOTE: A quick-fix is setting the env-variable DISABLE_V8_COMPILE_CACHE

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
trusktrcommented, Nov 6, 2020

The assignment to module.exports happens later in the queue:

it doesn’t seem possible to use import() in actual config files anyway.

Here’s how to import ES Modules in a synchronous way:

const deasync = require('deasync'); // powerful magic

const promiseSync = deasync((promise, cb) => {
  promise.then((result) => cb(null, result)).catch((error) => cb(error));
});

const importSync = (name) => promiseSync(import(name));

// Look, no await needed here!
const something = importSync('./something.js').default;

module.exports = {
  ...something,
  // ...
}

See deasync

Running with DISABLE_V8_COMPILE_CACHE=1 eslint . works great!

0reactions
mdjermanoviccommented, Nov 6, 2020

Awesome, thanks for sharing this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-restricted-imports - ESLint - Pluggable JavaScript Linter
Rule Details​​ This rule allows you to specify imports that you don't want to use in your application. It applies to static imports...
Read more >
babel-eslint does not allow dynamic import - Stack Overflow
I found the reason why this happens. It seems VSCode has internal javascript linter that is enabled even if eslint plugin is linting....
Read more >
[Solved] Eslint config for dynamic imports? - Meteor forums
Latest The problem you want to solve. I want to use ESLint and Webpack without babel-ESLint, but... Did anyone else manage to configure...
Read more >
eslint-plugin-import - npm
This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import ...
Read more >
eslint-plugin-import | Yarn - Package Manager
This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import names.
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