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

Local Config File Resolution throw error in file protocol #13359

Closed
zWingz opened this issue May 26, 2020 · 10 comments
Closed

Local Config File Resolution throw error in file protocol #13359

zWingz opened this issue May 26, 2020 · 10 comments
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 auto closed The bot closed this issue bug ESLint is working incorrectly documentation Relates to ESLint's documentation

Comments

@zWingz
Copy link

zWingz commented May 26, 2020

https://cn.eslint.org/docs/developer-guide/shareable-configs#local-config-file-resolution

I create my config @scope/eslint-config-myconfig in local, and install it by npm install file:../eslint-config-myconfig

eslint-config-myconfig

// index.js
module.exports = {
  parser: 'babel-eslint',
  extends: ['./base.js'],
};

// base.js
module.exports = {
  extends: ['other-config'],
  rules: {
  },
};

// vue.js
module.exports = {
  extends: ['@scope/eslint-config-myconfig', 'plugin:vue/essential'],
  rules: {
  },
};

project-1

module.exports = {
  extends: '@scope/eslint-config-myconfig/vue'
};

when i run eslint src, it throw error

Oops! Something went wrong! :(

ESLint: 7.1.0

ESLint couldn't find the config "@scope/eslint-config-myconfig" to extend from. Please check that the name of the config is correct.

The config "@scope/eslint-config-myconfig" was referenced from the config file in "/Users/my/scope/eslint-config-myconfig/vue.js".

If you still have problems, please stop by https://eslint.org/chat to chat with the team.

but it succeed after published to npm

Tell us about your environment

  • ESLint Version:
    7.1.0
  • Node Version:
    10.16.3
  • npm Version:
    6.11.3

Resolved

I used extends: ['./base'] to resolved it, but i diff to document

image

@zWingz zWingz added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels May 26, 2020
@anikethsaha
Copy link
Member

Thanks for the issue.

can you try with linking the package, like using npm link

@mysticatea
Copy link
Member

Hi.

What happens if you execute require("@scope/eslint-config-myconfig") in the vue.js file of eslint-config-myconfig package? It's what ESLint does.

If a file contains extends:"eslint-config-foo", ESLint loads it as similar to require("eslint-config-foo") in the file.

@zWingz
Copy link
Author

zWingz commented May 26, 2020

throw error Error: Cannot find module '@scope/eslint-config-myconfig', maybe it load from eslint-config-myconfig/node_modules

@zWingz
Copy link
Author

zWingz commented May 26, 2020

@anikethsaha as same as npm install file://

@anikethsaha
Copy link
Member

for modules, if you have them as dep, it should work irrespective of the path to the module.

are you using mono repo? like for Lerna, I guess the command is lerna link.

@mysticatea
Copy link
Member

throw error Error: Cannot find module '@scope/eslint-config-myconfig', maybe it load from eslint-config-myconfig/node_modules

OK, so this is the designed behavior. You have to write eslint-config-myconfig as working fine with this behavior.

I'm not familiar with lerna, so I mention another solution: I guess you can use extends:"./index.js" or something like instead of extends:"@scope/eslint-config-myconfig", because require("./index.js") in the vue.js should work fine.

@zWingz
Copy link
Author

zWingz commented May 26, 2020

@mysticatea yes, i use './base` to resolved, but the document recommend to use full-pkg-name

@mysticatea
Copy link
Member

Ah, I got it. So this looks a documentation issue. Because package names in extends are similar to require("package-name") and we should not write require() with packages what the dependencies field doesn't contain.


...In fact, recently Node.js has supported resolving self-references (nodejs/modules#306). So if you are using Node.js v12.16.0/v14.0.0 (or above) and the package.json of eslint-config-myconfig package contains exports field, extends:"@scope/eslint-config-myconfig" may work fine as well.

@mysticatea mysticatea added documentation Relates to ESLint's documentation and removed triage An ESLint team member will look at this issue soon labels May 26, 2020
@kaicataldo
Copy link
Member

@mysticatea Have you verified this is a documentation bug? If so, can you mark this as accepted and outline what you think the fix should be so someone from the community can make a PR?

@mysticatea mysticatea added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jun 21, 2020
@eslint-deprecated eslint-deprecated bot added the auto closed The bot closed this issue label Aug 26, 2020
@eslint-deprecated
Copy link

Unfortunately, it looks like there wasn't enough interest from the team
or community to implement this change. While we wish we'd be able to
accommodate everyone's requests, we do need to prioritize. We've found
that accepted issues failing to be implemented after 90 days tend to
never be implemented, and as such, we close those issues.
This doesn't mean the idea isn't interesting or useful, just that it's
not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Mar 18, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Mar 18, 2021
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 auto closed The bot closed this issue bug ESLint is working incorrectly documentation Relates to ESLint's documentation
Projects
None yet
Development

No branches or pull requests

4 participants