-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
require.resolve() on Node 10 unexpectedly returns local JSON file #35367
Comments
I looked through the change logs, but was not able to find which commit fixed this. I did find #18408, which might be related? I'm hoping such bug fix could perhaps be backported still to Node.js 10. But, I can also see how one might consider that as semver-major. I'd understand declining this. If declining, I do hope someone could let me know if there is a way this could be worked around by QUnit in the interim (until Node 10 reaches end-of-life). |
Out of curiosity, what is the behaviour for |
@aduh95 That's right:
I also found another way, which makes it look at
To my surprise, this works even when I misspell
Anyway, I think I'll go with adding |
If the project using QUnit has a local qunit.json file in the repository root, then the CLI was unable to find the 'qunit' package. Instead, it first found a local 'qunit.json' file. This affected an ESLint plugin with a 'qunit' preset file. This bug was fixed in Node 12, and thus only affects Node 10 for us. The bug is also specific to require.resolve(). Regular use of require() was not affected and always correctly found the local package. (A local file would only be considered if the require started with dot-slash like `./qunit`.) Ref nodejs/node#35367. Fixes #1484.
If the project using QUnit has a local qunit.json file in the repository root, then the CLI was unable to find the 'qunit' package. Instead, it first found a local 'qunit.json' file. This affected an ESLint plugin with a 'qunit' preset file. This bug was fixed in Node 12, and thus only affects Node 10 for us. The bug is also specific to require.resolve(). Regular use of require() was not affected and always correctly found the local package. (A local file would only be considered if the require started with dot-slash like `./qunit`.) Ref nodejs/node#35367. Fixes #1484.
Closing as v10.x reached end of life. |
What steps will reproduce the bug?
What is the expected behavior?
To return
/tmp/bug/node_modules/qunit/qunit/qunit.js
.What do you see instead?
It returns
/tmp/bug/qunit.json
.Additional information
This works as expected on Node.js v14.5.0, but it is broken on Node v10 LTS. As such, the QUnit CLI is broken for users that have a
qunit.json
file in their repository. The CLI is unable to startup due to local module resolution leading QUnit to import the JSON file, instead of thequnit
npm module.The code in question comes from qunit:/src/cli/require-qunit.js, which is meant to return what
require('qunit')
would return if run from the user's project.As such, results that point to local files that would normally need to be prefixed
./
are not expected to be returned, similar to howrequire('qunit')
in that directory, could not return the result ofrequire('./qunit')
.In the case of wikimedia/eslint-config this is not easily worked around, because the
qunit.json
in question is part of this module's public interface, exposed to npm users and to ESLint via eslintrc files, e.g."extends": "eslint-config-wikimedia/qunit"
.The text was updated successfully, but these errors were encountered: