-
Notifications
You must be signed in to change notification settings - Fork 144
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
False positive error for "Cannot use 'import.meta' outside a module" on a module file. #3639
Comments
It appears that this only happens if the module has ONLY dynamic imports. If I include a dummy static import it triggers the linter into realizing it is a module. So the issue appears (on the surface) to be a ES6 module detection issue. |
Please share a (minimal) test case to reproduce the issue. If i doubt, you can use the command-line version (or indirectly via |
We should be already able to put together the minimal test case with the details provided in the first issue description and the comment that follows it. The javascript scanner is currently going to lint a js file as module if it does "parse successfully as type module AND contain at least one import or export statement", see:
I think we may either choose to:
The first option (preferring "module" for .mjs files) is probably the one with less potential side-effect and it may be reasonable enough. @willdurand wdyt? |
I agree. |
Are there any workarounds besides renaming a file to .mjs? Maybe some dummy code or a comment I could add at the top of the file for it to be scanned as a module? When I encountered this yesterday, I went the route of renaming some files to .mjs, but I made a mistake and it resulted in my addon's options page not working after release. I use a build tool that doesn't allow me to specify file extensions, so I will always have to manually rename files after build to get around this bug, and manually renaming means the possibility of mistakes. The Chrome release of my extension is built using the same code/repo, but the Chrome scanner didn't have any issue with the files being named .js. It's a little troubling to have to do this extra manual step for only Firefox. |
Fixed by: #4399 |
Repro:
Include a module file that is dynamically inserted into the DOM.
Use an es6 module feature such as
import.meta.url
.^^^ Image from validation report of extension being uploaded to AMO
This file is an es6 module and has a
.mjs
extension. It is loaded via JS with atype='module'
.The code is correct and works properly on all browsers including FireFox (of course).
Is there a way to hint the linter to avoid this rejection? I'm not able to release my new extension version because of this.
The text was updated successfully, but these errors were encountered: