-
-
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 silently fails if the module is minified #3107
Comments
That’s very strange. (altho minifying a package never makes sense, ever - minification is something that should only ever be done by a top-level app) I’ll look into it. |
Thanks, let me know if you can't repro, but I was able to repro in a fresh project with the latest eslint and eslint-plugin-import
Not sure what you mean by this. In my case it's a TypeScript file that is compiled to a minifed JS esmodule, which is then distributed for use by legacy non-typescript esmodules. We use this plugin to ensure the imports using that esmodule are correct. |
Why would it need to be minified, though? Transpiling is fine, but minification is something else altogether. |
So that devs don't attempt to modify it. It's a hint to the developer that it's a build artifact of upstream source, and that they should be modifying the upstream source. This is a very standard and common practice for distributing libraries. For example: https://pixijs.download/v8.5.2/pixi.min.mjs This is PixiJS as an esmodule. If I'm using this in my project, I would hope:
Would get flagged by |
It's common for libraries that are generally consumed directly through html / browser scripts (via cdn downloads), since it reduces download size / time. But I would assert that it's an antipattern for libraries that are consumed through package managers and ultimately built into an app. It negatively impacts developer experience. Shit happens and people need to debug code, and if you're trying to figure out what a library is doing to investigate an issue, having it minified is a huge pain in the ass, with no real benefit. |
Why would a developer ever be modifying third-party code? If they are willing to do that in the first place, then they're already violating every best practice that exists, and no hint is going to stop them. For distributing libraries as a drop-in script tag, yes, but that's archaic and obsolete and from the earlier part of the past decade. npm packages are never minified. |
Can you provide the minified content of |
Not sure why you are getting so defensive, no offense was intended. Minified javascript is valid javascript, we aren't using npm to manage any front end dependencies, just a few dev tools like eslint and esbuild (to strip types out of TS, which we then load directly as an ESM). You would open an issue against a json parser that couldn't parse minified json, wouldn't you?
Edit: Also note some minifiers also do obfuscation as well, so you could end with something like:
(though in my case, I'm not obfuscating, just removing whitespace) |
Indeed, it's a bug, as I indicated previously, but it's always important to try to stop bad practices whenever they appear, and minifying a published package is one such bad practice :-) I'm also very confused; this isn't a published package it seems, but a relative file - why would you be linting build output of any kind? In your OP I would expect both |
In this case it's a legacy codebase that was created in 2016. When it was first created it was an AngularJS app. Then Google abruptly killed AngularJS, and in our wrath we swore off JS frameworks in favor of vanilla esmodules, vanilla web components, etc. ("frameworks are faddish, but vanilla is forever"). So new pages started just using vanilla esmodules like This seemed to work well and is very simple. No dependency on npm, no build steps, no file watchers, no bundlers. Write modular code, but just hit refresh to pick up any changes. Now of course, over time, we kept getting bitten by JS's lack of typing and so we wanted to start using TypeScript. However, there are a lot of So we introduced Eventually, all the We have not yet bitten the bullet on going all-in on adding npm to the critical path. Currently npm is not in the critical path at all. The I'm not claiming this system is perfect, but I think it's a valid design decision to avoid the baggage that comes with npm, since it introduces quite a bit of complexity, maintenance burden, and risk to the system. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hold on. Lets not mix tc39 concerns with eslint-plugin-import concerns. Linter failing silently is a bad failure mode, and I believe we should at least provide a crash report. Once we'll know what caused the fault, we can triage. |
To figure out where it crashes (to make it report it not silently) it'll help to have a way to reproduce this fault. @RPGillespie6 Can you please share some additional information about the minified file?
My thinking is, if we take a large open source library, run it through minification, and try to import from it - maybe we'll be able to reproduce this? |
I'm importing the modules natively in-browser with I also suspect this could happen to non-minified files as well, if the |
I have prepared a reproduction repository: https://github.com/soryy708/eslint-plugin-import-issue-3107 Indeed it fails to error on import of non-existent/non-exported as reported in this issue. Of note: We're using
|
In my reproduction repository, I debugged it down to:
What I don't know is:
|
The null was written to the cache in a previous visit, via:
Which invokes:
|
This failure is in fact not silent. If we would have set the environment variable
|
Looks like it's failing to match because the regex is looking for the word |
Indeed, seems like the regex could be tweaked to handle that case. |
This part of the regex:
Since |
…code This change adjusts the regex pattern used to detect modules to support detection on minified code. Fixes import-js#3107
I have 2 files:
If
bogus.js
is minified, eslint-plugin-import silently fails:Here's my eslint config:
Tested with eslint 8.X and 9.X, issue is present in both. Using
eslint-plugin-import:2.31.0
Edit: Actually, some types of minification work. For example:
Is this library using regex or something to detect exports instead of the file's AST? That's the only thing I can think of that would make it so that the absence of an optional semicolon causes silent failures
The text was updated successfully, but these errors were encountered: