-
-
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
Possible readme error for eslint-import-resolver-node #130
Comments
Just to follow up, I was able to get it to work this way, using this .eslintrc with the following options: "settings": {
"import/resolve": {
"paths": ["src/"]
}
}, It seems that the contents of |
Yeah, that is leftover from v0.10. I left the default behavior to minimize breakage to any config in the field. Going forward, the same config can b provided as indicated in the resolver-node README--though I'll double-check it for accuracy. Whipped it together trying to get the Webpack resolver out this week.
|
Ah, sorry, the version number info didn't make it in the email. That is indeed the only way to configure paths before v0.11--I just shipped the resolvers with 0.11. If you want to see the documentation for v0.8.1, you should be able to switch to the tag for that version. I believe that version of the README documents |
@msikma: I was just reading through your ESLint Gitter messages, and got a better understanding of what you were after. Would it be simpler to have the Node resolver use I generally bake my |
Oh yeah, I think that would make sense, definitely. To my knowledge the only way to have your own import directory is to specify it using |
Hi, |
I am having the same problem as @jazzdragon. Have tried both methods and still getting these missing require hits. |
NODE_PATH is deprecated and considered a bad practice; it should work while node supports it, but I'd recommend migrating away from it. |
What's a good alternative? |
All your requireable things should be in the local |
So I know this is probably getting off track of this thread, but regarding the deprecation. I did a bunch of reading and the recommended practices. They all seem to recommend keeping tests side by side with the files they test for. So we usually keep our tests separate. We use the The other approach I saw was that you can reference packages in Super interested in recommendations :) |
@ShaunEgan i highly disagree that colocating tests is a best practice; I think the opposite. However, when keeping tests separate, I simply use |
Cool, I agree with your approach. I really dislike them all in the same place. Thanks for the advice! |
To further go off topic here, I'm really not sure why NODE_PATH is considered a bad practice, especially if it works great and makes code more readable and easier to maintain.
makes much more sense than:
|
We're setting a local path to our project js files. Relative paths are just too error prone and frustrating ("ugh, forgot/added an extra
Jest takes the configuration {
"modulePaths": [
"<rootDir>/app/assets/",
"<rootDir>/vendor/assets/javascripts/",
]
} Webpack takes the configuration config = {
resolve: {
extensions: ['.js'],
modules: [
path.resolve('app/assets'),
path.resolve('vendor/assets/javascripts'),
path.resolve('node_modules'),
],
}
} Mocha doesn't have a way out of the box, as far as I can tell, but I was able to work around it using the import path from 'path';
import AppModulePath from 'app-module-path';
const jsPath = path.normalize(__dirname + '/../../app/assets/');
const vendorPath = path.normalize(__dirname + '/../../vendor/assets/javascripts');
AppModulePath.addPath(jsPath);
AppModulePath.addPath(vendorPath); I'm not aware of a way to get around it using browserify, so you may be stuck with modifying And to make settings:
import/resolver:
node:
moduleDirectory: [app/assets, node_modules] |
@jazzdragon because it makes it impossible to look at your code and know where something is being required from. node is not going to implement support for it with ES modules also, so you'll be well advised to migrate off of it. It's not important what makes sense to you - it's important what will make sense to every node/JS developer, and that's "the node require algorithm". @mockdeep it's not officially deprecated in the sense that they won't be removing it for The fact that tools like jest and webpack give you the ability to approximate NODE_PATH doesn't make it a good pattern; it just means those tools want to cater to the users who want that pattern (whether it's a good one or not). The proper solution, if you dislike chains of |
@ljharb why is it better to pull things out into npm installed modules? The only issue I see mentioned is the possible performance of it, but I haven't seen any benchmarks to convince me that there's a difference worth worrying about, nor have we had any performance issues related to package loading. Having to pull things out into npm modules just sounds like a pain in the butt, though. |
@mockdeep it encourages the proper encapsulation. It's got nothing to do with performance (that's almost never important when programming), it's about maintainability, readability, encapsulation, reusability, etc. In general, it's easy to consolidate but hard to separate, so whenever you get the opportunity to separate things, take it. |
It's very striking how this thing just keeps coming up time and again, though. Every once in a while someone mentions NODE_PATH and the need to do imports relative to the current module, and every time it's the same story: best practices, small modules, don't mess with Node's way of doing things. Regardless of what any one of us might think, to me this does not indicate simply a failure to communicate how Node works, but a disagreement among a significant amount of Node users on how it should work in the first place. The numerous iffy workarounds are testament to this. I don't think it's correct to say it's "widely considered a bad practice" because this issue just refuses to die. In my view, the core problem is that the Node module resolution algorithm doesn't support import paths relative to the current package—only to the current file, to the filesystem root, or to any file (not even package, necessarily) inside |
@ljharb while I can certainly get on board with the idea that good encapsulation is important, it seems like there are a lot of ways to encourage it without taking on the additional burden of maintaining a bunch of separate npm packages. It seems like we're exchanging one source of pain for another, not to mention using paths as a source of pressure towards that goal seems a little indirect and easy to draw the wrong conclusions from. In our case we encourage better encapsulation explicitly via our linters and having a strong culture around code review. |
Hi there. I'm currently attempting to get this plugin working with (the equivalent of) a custom NODE_PATH. Was looking at the eslint-import-resolver-node documentation, which says to add an
import/resolver
key to the.eslintrc
file, but after checking the code I see that it actually looks forimport/resolve
(inlib/core/resolve.js
).I'm not sure if I'm missing something, or if there's a discrepancy.
Relevant versions:
The text was updated successfully, but these errors were encountered: