Skip to content
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

Fix: wrong 'plugin-missing' error on Node.js 12 (fixes #11720) #11722

Merged
merged 3 commits into from May 16, 2019

Conversation

mysticatea
Copy link
Member

@mysticatea mysticatea commented May 15, 2019

What is the purpose of this pull request? (put an "X" next to item)

[X] Bug fix: #11720 (wrong plugin-missing errors on Node.js 12)

What changes did you make? (Give an overview)

This PR fixes wrong plugin-missing errors on Node.js 12.

The config array factory distinguishes by the following way if a MODULE_NOT_FOUND error was plugin's or came from inside of the plugin.

error.code === "MODULE_NOT_FOUND" && error.message.includes(request)

Because the error.message was "Cannot find module '${request}'" until Node.js 12.

Since Node.js 12, the error.message contains the require stack. For example:

Cannot find module 'eslint/lib/util/glob-util'
Require stack:
- C:\Users\t-nagashima.AD\dev\sandbox\node_modules\eslint-plugin-import\lib\rules\no-unused-modules.js
- C:\Users\t-nagashima.AD\dev\sandbox\node_modules\eslint-plugin-import\lib\index.js
- C:\Users\t-nagashima.AD\dev\sandbox\node_modules\eslint\lib\cli-engine\config-array-factory.js
- C:\Users\t-nagashima.AD\dev\sandbox\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js
- C:\Users\t-nagashima.AD\dev\sandbox\node_modules\eslint\lib\cli-engine.js
- C:\Users\t-nagashima.AD\dev\sandbox\node_modules\eslint\lib\cli.js
- C:\Users\t-nagashima.AD\dev\sandbox\node_modules\eslint\bin\eslint.js

Then, error.message.includes(request) (that request is eslint-plugin-import in that case) was true as unexpected.

Now, the config array factory checks error.requireStack if it existed. the try blocks of resolving and loading are separated.

Is there anything you'd like reviewers to focus on?

Nothing in particular.

@mysticatea mysticatea added bug ESLint is working incorrectly core Relates to ESLint's core APIs and features accepted There is consensus among the team that this change meets the criteria for inclusion labels May 15, 2019
@not-an-aardvark
Copy link
Member

Instead of matching on error.message, would it be possible to check where the error is thrown from?

It seems like "plugin missing" errors will always cause ModuleResolver.resolve to throw, and errors from plugin loading will cause require to throw. So we could distinguish the errors by just having two separate try blocks. (This is what the previous implementation did.)

@mysticatea
Copy link
Member Author

Oh. You are right.

@mysticatea
Copy link
Member Author

I updated this PR.

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a small suggestion.

lib/cli-engine/config-array-factory.js Outdated Show resolved Hide resolved
@mysticatea mysticatea added this to Ready to merge in v6.0.0 May 16, 2019
@not-an-aardvark not-an-aardvark merged commit 7c8e86b into master May 16, 2019
v6.0.0 automation moved this from Ready to merge to Done May 16, 2019
@not-an-aardvark not-an-aardvark deleted the fix-plugin-missing branch May 16, 2019 23:36
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Nov 13, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Nov 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features
Projects
No open projects
v6.0.0
  
Done
Development

Successfully merging this pull request may close these issues.

ESLint 6.0.0-alpha.1 has a confusing error message for some plugins that crash on load
2 participants