-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
node resolver: respect NODE_PATH #142
Comments
Hi. Is this being worked on? |
I'd prefer we not support NODE_PATH - it's deprecated, and node won't be implementing it for ES Modules. |
As far as I know (and reading from the docs) From https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
Doing a overly-simplistic search on Please support this! |
At the very least, it's highly discouraged in the community to use it - and as I said, node has explicitly indicated that they will never implement anything like it for native ES Modules, so in the fullness of time, you'll effectively be forced off of the pattern anyways. |
@ljharb do you have a link to where future support for |
Apps created with |
@mockdeep support won't be dropped since ESM is new. It just won't be added, because the only folder you should be importing from is node_modules. Just because something is used, even in CRA, doesn't make it a good idea ¯\_(ツ)_/¯ |
I for one would vote for "when resolving Similarly, when ESM lands, I would vote for "when resolving |
Ok, so let me try and understand something, because I imagine there must be a sane way to do it: In a sizeable react application, a common way to organize it is to have a Then in the pages you usually want to have access to many of these components, and it's a bit of a hassle to have to type a relative path to all your app-specific components in order to import them in the context you want them. Is there a way to achieve doing things like this below? import MyComponent from 'components/MyComponent'; instead of having to do something like this... import MyComponent from '../../../../components/MyComponent'; ...and be able to make this eslint plugin pick that up and realize that there's no missing |
@ryan-roemer without a doubt, if this module does support @gnapse No, you should be using the dots. If you don't like the dots, extract things to a separate npm-installed package. alextes/javascript-best-practice#1 (comment) may be helpful/relevant. |
@ljharb I have an alternative solution that the issue you link to does not cover. It's import MyComponent from 'my-app/components/MyComponent'; This is referring to Would this be considered bad practice too? If so, why? |
@gnapse I'm not sure how ember does "considered implicitly as a package", but if it does it using one of the techniques in that link, then the mentioned caveats apply - if not, then that's a very bad practice, yes. |
@ljharb you didn't answer my question. Is there a conversation you can point us to that discusses how node is planning to leave off supporting
This is a non-argument. It doesn't make it a bad idea either. |
@mockdeep I agree; I was responding to a non-argument ("it's used in CRA") with an equally valid non-argument. As to your question: the official node module proposal indicates this - it's the concrete plan of record, and is definitely not going to change. |
You use such strong wording. Isn't a draft something that is by definition subject to change? |
@mockdeep I'm using the same strength as the author of that draft; neither they nor anyone I'm aware of on the node TSC wants that specific aspect of the draft to change. |
Referring to stuff by relative paths is not always a good idea. I tend to organize my apps as modularly as possible. Within what I consider a module (a self-contained feature arranged in a set of files within a directory) I use relative paths because everything within that module is tightly coupled. But when crossing boundaries across modules (e.g. one module importing another module) I dislike using the relative path approach to import the other module's There you have an explanation of the logic behind the feature request. Can you explain me what is wrong with considering your own app as a package, alongside all the other packages in I agree that other things, like wanting to put several other folders in |
Ignoring for a moment whether or not using from the example there: # .eslintrc.yaml
settings:
import/resolver:
node:
paths:
# an array of absolute paths which will also be searched
# think NODE_PATH
- /usr/local/share/global_modules If you use This issue was more about whether the Node resolver should automatically check Given that, I'll close this issue and recommend that you encode your runtime |
@benmosher -- Thanks for taking the time to review this issue. Having In particular, our multi-repo wrangling tool A totally weird and nonstandard way of doing things, but also one completely supported by the current I've been having to one-off disable things like: const foo = require("foo"); // eslint-disable-line import/no-unresolved I encourage you to reconsider and just support the spec, so that when this plugin says it has a "Node resolver", that resolver actually resolves like Node does. Thanks! As an alternative, do you have an example that would work instead with the actual |
Or, putting it a different way, there's no downside to doing At the end of the day, I don't think all of us have to agree on whether or not |
I'd disagree: the lint-time I agree that 99% of the time no one is using it, and 99% of the remaining 1% it would work fine. But it's one more thing to maintain and given that I suspect it's generally not needed, I don't think it's worth the investment. (sorry. 😅) Fortunately, if you want to use the lint-time // .eslintrc.js
const path = require('path') // assuming you use cwd-relative paths in your NODE_PATH
exports.settings = {
"import/resolver": {
node: { paths: process.env.NODE_PATH.split(":").map(path.resolve) }
}
} and I think that will give you the behavior you're looking for. |
@benmosher -- All our eslint configs are YAML. And chance there's a YAML version of that? |
No way to use functions in YAML config AFAIK. But it's easy enough to convert. (I prefer YAML as well, but it is handy to be able to use the power afforded by JS config when needed) |
After a bunch of research to try to get JSON {
"parser": "babel-eslint",
"env": {
"browser": "true",
"node": "true",
"jest": "true"
},
"extends": "airbnb",
"settings": {
"import/resolver": {
"node": {
"moduleDirectory": ["node_modules", "src/"]
}
}
}
} YAML ---
parser: babel-eslint
env:
browser: 'true'
node: 'true'
jest: 'true'
extends: airbnb
settings:
import/resolver:
node:
moduleDirectory:
- node_modules
- src/ |
Co-authored-by: SukkaW <[email protected]>
Automagically split (on
path.delimiter
),path.resolve
relative to CWD, and add topaths
.(inspired by #130)
The text was updated successfully, but these errors were encountered: