-
-
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
eslint-plugin-import
breaks eslint
if no package.json
-file is present
#2096
Comments
We should definitely have a better error message - but why would you ever be running eslint outside of a node project with a package.json? global installs and personal configs are deprecated. |
I had it running without a In order to do so, I create temporary I think this is pretty much an edge-case. My current solution is to create a |
It's certainly a scenario that's incompatible with this plugin. We should improve the error message here, though. |
Currently, `eslint-plugin-import` doesn't support workspaces without a `package.json`-file in it. The issue describing this matter is import-js/eslint-plugin-import#2096
I also don't have a package.json, just because I'm not deploying any node modules in my project and therefore I simply don't need a package.json. IMHO this should be considered as a bug as it worked before without a package.json. |
Hi, |
@GiladShoham I'm a bit unclear how any workspace workflow could function without package.json (in a JS project); lerna, yarn, npm, rush, etc all use package.json for their workspaces implementation; even bazel has one in the root by default for JS projects. Things inside node_modules always have |
@ljharb I'm experiencing similar issues under I think the requirement of a |
@ljharb Using bit, you don't have a package.json in your workspace (only with your final packages). but the lint environment is a workspace. which means you don't have a package.json. |
@GiladShoham the pattern you describe will break all tooling in the ecosystem that expects package.json to be present - in other words, you can only lint a node project, and it's not a node project unless there's a package.json. The best option is to fix bit to follow node conventions instead of radically deviating from them. Certainly the error message can be made more descriptive. |
@ljharb sorry, but I completely disagree. The purpose of the package.json is to create a npm package to share a project. If you don't want to share your project, you don't need a npm package and therefore also no package.json. Furthermore eslint is for linting any javascript code, not only javascript code which is part of a npm package. So why does this restriction exist for eslint-plugin-import? I'm using several other third party plugins and not one of them is making this restriction. And this has also nothing to do with not following node conventions. There aren't any node conventions which force you to create a npm package. Your arguments are not convincing and I'm still having the opinion, that this behavior should be considered as a bug. |
I agree with @g1thuser on this. At the end of the day we are sorting imports* here, you will be hard-pressed to convince everyone that a sorting algo requires a node project structure. * I know more than sorting is going on, just being a little facetious |
I agree with @g1thuser Changing bit is a discussion that can be done, but it's not really related to this issue (I don't see it changes for many reasons). The main issue is that a plugin completely break eslint of a result of not having the package.json which is not a must. |
@g1thuser that's not the only purpose of package.json. node itself uses it even for non-published apps for a few purposes. There ABSOLUTELY are node conventions that force a package.json, in other words. You're welcome to opt out by not using this plugin, but javascript without a package.json is JS that's stuck in the early part of the previous decade, so I'm not concerned with linting that. In particular, eslint-plugin-import doesn't apply for anything except node, and only recently, ESM - but we don't truly yet support native ESM, only transpiled ESM, so there's not yet a use case to omit package.json for this plugin. |
🔥 Absolute savage |
As I said, I'm happy to make for a better error message, but so far the only commentary here has been "but my non-package.json use case is valid!" and nobody has actually provided repro repo where it would be reasonable to expect the plugin to work, but it fails. With such a repo, I'd be happy to fix the problem. Without one, the only improvement that's possible is to ensure a better error message (but i'd still need a repro repo to figure out the call stack that the error is originating from). |
This is definitely wrong. I'm using this plugin for my typescript projects, which aren't node projects and therefore don't require a package.json. Furthermore I'm using eslint also for the relevant gulpfile.jsm files in these projects for the build and even for their .eslintrc.js files. Only because you don't see any reasonable use cases to use this plugin without a package.json, this doesn't mean that there aren't any. And yes, my non-package.json use case is valid and, of course, also the one from @GiladShoham . But as you have asked for a repro repo, here it is. The two eslint config files in this repo are crashing eslint with different stack traces. The included rules are the only rules from eslint-plugin-import, which I'm using, which cause a crash. All other rules from this plugin are fine for me. |
@g1thuser what you're using it for doesn't really have any bearing on what it's intended for. gulp is a node tool, for the record, and it's a best practice for node tools to be npm-installed per-project via package.json. Thanks for the repo; i'll take a look. |
@ljharb I don't care about best practices, if they are bringing only disadvantages to me. I have some very good reasons to use a central node repository in my case and gulp is, of course, npm installed in this repository. |
First off, thanks for providing this library. :) At $work, we use Code::TidyAll to lint and tidy files of various languages and file types. This library (for reasons) copies files over to a temporary directory before linting or fixing them. In our case this worked fine until So, I just wanted to point out that this kind of use case exists. We will work around this, but it did seem surprising that this was the case. |
Being language-agnostic is simply not something that can ever be relied upon from individual packages in an ecosystem. I'm sorry for the inconvenience, and I'm certainly happy to accept PRs that:
Beyond that, if a tool is relying on something not needing to be present that the ecosystem expects is always present without exception, the tool is guaranteed to break in unpredictable ways. Note as well that |
Thanks, @ljharb. I appreciate your thoughts. From my perspective, having a clearer error message would have been really helpful in debugging this. |
I'm experiencing this issue as well, I use pnpm for my package manager which allows me to use |
@RubyBB even if it didn't crash, it wouldn't be useful, because literally nothing in the ecosystem besides pnpm (apparently) uses |
I wrote a quick dirty solution for my problem. scripts:
lint:es: >
node -e "console.log(JSON.stringify(require(\"yaml\").parse(require(\"fs\").readFileSync(\"./package.yaml\", \"utf8\"))))" > package.json &&
pnpm exec eslint . --fix && rm package.json || rm package.json |
That seems like a good thing to do all the time anyways, since the entire JS ecosystem, including node itself (which checks "type", "imports", "exports", and "name"), only works with |
@ljharb node checks package.json inside the specific node_module, which makes sense to validate. Still, if you want this to be validated, it shouldn't crash the entire eslint process. |
If you npm install and delete package.json then what you’ve broken is your ability to manage your project’s dependencies; I’m not concerned about this plugin in that scenario. See #2096 (comment); I’m happy to avoid the crash and provide a better error tho. |
If there is no
package.json
-file in the file to check (or any parent directory), theeslint
-run fails due to this piece of code:https://github.com/benmosher/eslint-plugin-import/blob/802ce7d49d912289d590f735bf9bd2d931064863/src/core/packagePath.js#L11-L12
Following error is reported:
The text was updated successfully, but these errors were encountered: