oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.27k stars 2.77k forks source link

`@eslint/eslintrc` `FlatCompat` / `import-fresh` throws an error in Bun #13346

Open controversial opened 3 months ago

controversial commented 3 months ago

What version of Bun is running?

1.1.24+85a329911

What platform is your computer?

Darwin 24.1.0 arm64 arm

What steps can reproduce the bug?

The FlatCompat class exported by @eslint/eslintrc is designed to help “legacy” eslint configs (pre-flat config) work with eslint 9+.

The following produces an error in bun:

import { FlatCompat } from '@eslint/eslintrc';
const compat = new FlatCompat();
const config = compat.extends('eslint-config-airbnb'); // or any “legacy” eslint config
console.log(config);

What is the expected behavior?

// node test.js
[
  {
    rules: {
      'accessor-pairs': 'off',
      'array-callback-return': [Array],
      'block-scoped-var': 'error',
      complexity: [Array],
      'class-methods-use-this': [Array],
      'consistent-return': 'error',
      curly: [Array],
      'default-case': [Array],
...

What do you see instead?

An error from within the import-fresh module

// bun test.js

27 | 
28 |    delete require.cache[filePath]; // Delete module from cache
29 | 
30 |    const parent = require.cache[parentPath]; // If `filePath` and `parentPath` are the same, cache will already be deleted so we won't get a memory leak in next step
31 | 
32 |    return parent === undefined ? require(filePath) : parent.require(filePath); // In case cache doesn't have parent, fall back to normal require
                                                               ^
TypeError: Cannot read config file: /Users/luke/Developer/misc/bun-eslint-compat/node_modules/eslint-config-airbnb/index.js
Error: parent.require is not a function. (In 'parent.require(filePath)', 'parent.require' is undefined)
Referenced from: 
      at /Users/luke/Developer/misc/bun-eslint-compat/node_modules/import-fresh/index.js:32:59
      at loadJSConfigFile (/Users/luke/Developer/misc/bun-eslint-compat/node_modules/@eslint/eslintrc/lib/config-array-factory.js:237:16)
      at _loadConfigData (/Users/luke/Developer/misc/bun-eslint-compat/node_modules/@eslint/eslintrc/lib/config-array-factory.js:638:42)
      at _loadExtends (/Users/luke/Developer/misc/bun-eslint-compat/node_modules/@eslint/eslintrc/lib/config-array-factory.js:810:25)
      at _normalizeObjectConfigDataBody (/Users/luke/Developer/misc/bun-eslint-compat/node_modules/@eslint/eslintrc/lib/config-array-factory.js:749:25)
      at _normalizeObjectConfigData (/Users/luke/Developer/misc/bun-eslint-compat/node_modules/@eslint/eslintrc/lib/config-array-factory.js:694:20)
      at create (/Users/luke/Developer/misc/bun-eslint-compat/node_modules/@eslint/eslintrc/lib/config-array-factory.js:489:20)
      at config /Users/luke/Developer/misc/bun-eslint-compat/node_modules/@eslint/eslintrc/lib/flat-compat.js:247:47)
      at/Users/luke/Developer/misc/bun-eslint-compat/eslint/bun.js:3:23

Bun v1.1.24 (macOS arm64)

Additional information

No response

alex-demchenko commented 2 weeks ago

still exists in 1.1.33 it blocks for use ESLint 9

Yasamato commented 2 weeks ago

For context:

$ bunx --bun eslint .

Oops! Something went wrong! :(

ESLint: 9.13.0

TypeError: Cannot read config file: /node_modules/eslint-config-next/core-web-vitals.js
Error: parent.require is not a function. (In 'parent.require(filePath)', 'parent.require' is undefined)

File content: node_modules/eslint-config-next/core-web-vitals.js:

module.exports = {
  extends: [require.resolve('.'), 'plugin:@next/next/core-web-vitals'],
}

Directly running bun --bun ./node_modules/eslint-config-next/core-web-vitals.js gives no errror.

Minimal setup to reproduce:

// eslint.config.mjs
import { FlatCompat } from "@eslint/eslintrc";
const compat = new FlatCompat();

export default [...compat.extends("next/core-web-vitals")];

package.json:

{
  "devDependencies": {
    "@eslint/eslintrc": "^3.1.0",
    "eslint-config-next": "^15.0.1"
  }
}

Now run: bun install && bunx --bun eslint .