Comments (8)
I can reproduce this locally. Thanks for the detailed analysis of the cause!
https://github.com/StewEucen/eslint-bug-with-jest?tab=readme-ov-file#cause
Retrier#retry()
usesPromise
declared inlib.es2015.iterable.d.ts
fs.readFile()
usesPromise
declared inlib.es5.d.ts
So it seems that in Node.js different operations may use different Promise
constructors?
@nzakas perhaps @humanwhocodes/retry
could check if the result is a thenable instead of checking result instanceof Promise
?
from eslint.
I can update retry
. Never occurred to me that there might be a promise from another realm involved.
from eslint.
A new version of @humanwhocodes/retry
was released as a patch version that should fix this.
from eslint.
Here's a PR to update the dependency: #18416
from eslint.
The Promise
object returned by fs.readFile
is from a different realm:
This only occurs when the Node.js process is launched with the --experimental-vm-modules
flag. It may have something to do with Jest's experimental ESM support, which is enabled by the flag.
from eslint.
- Thank you for your confirmation :)
So it seems that in Node.js different operations may use different Promise constructors?
- I think that since
fs
is old package, it uses polyfill Promise class.
-
I have already found two ways to fix now.
-
Change argument of
#retry()
function to async in ESLint repository.- return retrier.retry(() => fs.readFile(...) + return retrier.retry(async () => fs.readFile(...)
-
Change the logic to confirm Promise in
#retry()
of@humanwhocodes/retry
repository.- if (!(result instanceof Promise)) { + if ( + !(result instanceof Promise) + && (!result || typeof result.then !== 'function') + ) {
-
-
I think that
2.
is a fixing ad-hoc, thus we can select1.
from eslint.
- Thank you for your information
- I used
--experimental-vm-modules
on run Jest, it was due to the following reasons.
-
I had used
ESLint#lintFiles()
in Jest with[email protected]
. As we know, Jest works as CommonJS. But It did not require to use--experimental-vm-modules
flag. -
I changed the code to fit Flat Config with
9.1.1
, but it was not work. Because new code ofESLint#lintFiles()
uses dynamic import.https://github.com/eslint/eslint/blob/v9.1.1/lib/eslint/eslint.js#L317
async function loadFlatConfigFile(filePath) { ... const config = (await import(fileURL)).default; ... }
https://github.com/eslint/eslint/blob/v9.1.1/lib/eslint/eslint.js#L369
async function calculateConfigArray(eslint, { ... }) { ... if (configFilePath) { const fileConfig = await loadFlatConfigFile(configFilePath); ... } ... }
https://github.com/eslint/eslint/blob/v9.1.1/lib/eslint/eslint.js#L815
class ESLint { ... async lintFiles(patterns) { ... const configs = await calculateConfigArray(this, eslintOptions); ... } ... }
-
To solve the problem, I added a
--experimental-vm-modules
flag for Jest script.https://github.com/StewEucen/eslint-bug-with-jest/blob/main/package.json#L7
{ "scripts": { "test": "export NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\"; jest --forceExit" }, }
-
And then, I got the behavior that I reported in this issue.
from eslint.
@nzakas @mdjermanovic @fasttime
- Thank you for your work related to this issue.
- I am going to use ESLint patched version for my repository.
from eslint.
Related Issues (20)
- Docs: func-style docs are confusing HOT 1
- Docs: Unexpected file matching behavior when using `ignores` without `files` HOT 12
- Bug: No files matching the pattern "linebreak-style: [2, windows]" were found. HOT 3
- Change Request: Add autofix for func-style HOT 7
- Scheduled release for May 31st, 2024 HOT 1
- Bug: --inspect-config should always download the latest @eslint/config-inspector? HOT 5
- Change Request: RuleTester should allow testing for a missing node argument in the report HOT 7
- Bug: possible `no-constructor-return` false negative with nested blocks HOT 10
- Bug: Eslint 9 CLI doest work HOT 2
- Bug: ignores key is not ignoring the specified files/directory HOT 1
- Bug: `No matching configuration found` warning for code block matched only by non-universal patterns HOT 2
- Docs: CommonJS examples HOT 8
- Change Request: Supporting custom rule usage for ESModule projects HOT 4
- Cannot read config file: eslint.config.mjs HOT 4
- Bug: Out of Memory Error with 203 files HOT 1
- Providing non-default extensions via CLI. HOT 4
- Question: Unexpected key "typescript" found HOT 1
- Bug: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory HOT 2
- Change Request: Enhancement to the Node API to way to get list of all available rules before running HOT 2
- Bug: (v8) eslint@8 dep file-entry-cache@6 deprecated transient dependencies HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint.