-
Notifications
You must be signed in to change notification settings - Fork 3.4k
EXPORT_ES6 mode import.meta.url is not supported #8729
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
Comments
Whoops, that was my fault. Originally I was using An idea might be to use |
Another option is to check for the existence of |
Just wanted to chime in on this conversation, the project I'm working on recently ran into this issue where import.meta.url isn't available (we tried to polyfill it through . I think it might make sense for this into an opt-in flag where people who are targeting an environment where https://github.com/emscripten-core/emscripten/pull/8306/files#diff-ae40e645f84e893ce5d037b5efc53be6R2849
|
Wouldn't checking the existence of it also succeed if it's been polyfilled? Meaning less code and settings for the same goal? Or do you mean that there maybe some people who wouldn't want to use import.meta.url even if it's available? |
If I'm understanding your suggested approach correctly, I think that would end up being more code being delivered to clients since it would need to be a runtime check. In general I think putting the flexibility into the hands of the emsdk user is better here because there's a lot of variables in the module's running context that will be unknown to emscripten. For example, some projects might be going through webpack and webworkers, using a loader like the one shown here: All of these things are workaroundable, but it feels to me like the simplest fix would be to have emscripten default to something reasonable but options to opt-in to more future facing functionality, that way its easy for a user to fix without code changes in emscripten if they run into a weird situation. |
Out of curiosity, what did you use as the polyfill? Something that would work in an ES6 Module and web worker? |
We tried using this webpack loader - https://www.npmjs.com/package/@open-wc/webpack-import-meta-loader Which I believe should work fine for normal main thread usage, but does not function on a webworker. Hence the need to compile to ES6 but also not-use the import.meta. |
That sounds reasonable, since we have multiple reports of people hitting this problem. |
Thinking about this again, perhaps it's better to just just import.meta behind both For the people having issues with this, did the old |
Neither technique really worked for us, we're currently working around it with the It would be great if we could get it working without the |
This sounds fairly urgent to fix since it is a regression - @VirtualTim do you have time to look into it? |
Yeah sorry, I've been busy with other stuff. I'm seeing if there's any better alternatives, however Webpack is missing it, but you can use this plugin to add support. So what is the minimum environment that I should be targeting? |
I think for me personally, the webpack plugin that is referenced along with the fact that rollup already merged in their fix should resolve my initial issue (though still need to test that theory). However the general question for this project of "what is the minimum environment that I should be targeting?" is still a very important question.
For forward compatibility though, creating a useful way to turn on optional features is great. I have personally come to like typescript's lib option which provides a very detailed but organized solution to turning on future features that aren't currently part of the tc39 stage 4 spec. |
Also, if someone comes here and is curious how to get babel@7 to work with the import.meta.url, it's not supported by default, you have to add a plugin @babel/plugin-syntax-import-meta. This is also true for jest since jest uses babel in the background. To fix this for jest, you'll have to add the babel-jest library and the plugin mentioned above and override the default babel settings jest has baked in. Honestly after testing the fix here... (IMO) I'm having to add a lot of extra packages as work arounds because even though the browsers support this feature, the tooling doesn't. |
We're also hitting this issue on our web worker C++ code. The problem for us is that https://www.npmjs.com/package/@open-wc/webpack-import-meta-loader plugin converts import.meta to use "window. ..." instead but web worker doesn't have "window. ..." object. |
Can't we just make this configurable through a flag like Then everyone can choose the most appropriate output for their situation. |
So if Change the check to:
I didn't think |
@kkimdev, @k2snowman69, @benjamind I do want to fix this, but I'm not sure what the best solution would be that works for everyone. If it doesn't, can you list the options out of |
My only concern would be that your tying import.meta.url to pthreads which doesn't seem like the correct association as they do seem like two separate features but I'll leave that to the maintainers. Given that disassociation, I personally would go down the route of a Currently the flags I'm using to build are |
I'm away on vacation at the moment so can't check our exact flags but I believe we also use |
Does |
This is because inside a ES6 module pthread (AKA a webworker in strict mode) there's no access to the DOM, so no access to |
A webworker ES6 module doesn't have access to 'document.currentScript'. 'import.meta' was the only way I could see to achieve that functionality. Fixes #8729. Since this appears to fix the issue for everyone who commented on #8729, and no one proposed any better ideas, this is my suggestion. It would be nice to use import.meta everywhere, and browsers seem to have good support, however the tooling appears to be lagging a bit behind.
For those using the CI tools using trzecieu's docker build, VirtualTim opened an issue over for the docker image. Here's the link if you want it for tracking purposes! |
This fixes the problem reported by emscripten-core#9233 and by emscripten-core#8729 while fixing the regression bug causes by emscripten-core#8940
Hey there! Any update on this? Cheers! |
) A webworker ES6 module doesn't have access to 'document.currentScript'. 'import.meta' was the only way I could see to achieve that functionality. Fixes emscripten-core#8729. Since this appears to fix the issue for everyone who commented on emscripten-core#8729, and no one proposed any better ideas, this is my suggestion. It would be nice to use import.meta everywhere, and browsers seem to have good support, however the tooling appears to be lagging a bit behind.
…mscripten-core#9234) This fixes the problem reported by emscripten-core#9233 and by emscripten-core#8729 while fixing the regression bug causes by emscripten-core#8940
This setting was added (IIUC) as a temporary workaround for the lack or support for `import.meta` in browser and tooling. However `import.meta` has been at stage 4 for almost 5 years now: tc39/proposal-import-meta#21 Webback (released in 2020) also has builtin support for `import.meta`, so I would hope the use case for disabling this setting no longer exists. See emscripten-core#9234 and emscripten-core#8729
Is anyone still using the |
This setting was added (IIUC) as a temporary workaround for the lack or support for `import.meta` in browser and tooling. However `import.meta` has been at stage 4 for almost 5 years now: tc39/proposal-import-meta#21 Webback (released in 2020) also has builtin support for `import.meta`, so I would hope the use case for disabling this setting no longer exists. See emscripten-core#9234 and emscripten-core#8729
This setting was added (IIUC) as a temporary workaround for the lack or support for `import.meta` in browser and tooling. However `import.meta` has been at stage 4 for almost 5 years now: tc39/proposal-import-meta#21 Webback (released in 2020) also has builtin support for `import.meta`, so I would hope the use case for disabling this setting no longer exists. See emscripten-core#9234 and emscripten-core#8729
This setting was added (IIUC) as a temporary workaround for the lack or support for `import.meta` in browser and tooling. However `import.meta` has been at stage 4 for almost 5 years now: tc39/proposal-import-meta#21 Webback (released in 2020) also has builtin support for `import.meta`, so I would hope the use case for disabling this setting no longer exists. See emscripten-core#9234 and emscripten-core#8729
This setting was added (IIUC) as a temporary workaround for the lack or support for `import.meta` in browser and tooling. However `import.meta` has been at stage 4 for almost 5 years now: tc39/proposal-import-meta#21 Webback (released in 2020) also has builtin support for `import.meta`, so I would hope the use case for disabling this setting no longer exists. See emscripten-core#9234 and emscripten-core#8729
This setting was added (IIUC) as a temporary workaround for the lack or support for `import.meta` in browser and tooling. However `import.meta` has been at stage 4 for almost 5 years now: tc39/proposal-import-meta#21 Webback (released in 2020) also has builtin support for `import.meta`, so I would hope the use case for disabling this setting no longer exists. See emscripten-core#9234 and emscripten-core#8729
This setting was added (IIUC) as a temporary workaround for the lack or support for `import.meta` in browser and tooling. However `import.meta` has been at stage 4 for almost 5 years now: tc39/proposal-import-meta#21 Webback (released in 2020) also has builtin support for `import.meta`, so I would hope the use case for disabling this setting no longer exists. See emscripten-core#9234 and emscripten-core#8729
This setting was added (IIUC) as a temporary workaround for the lack or support for `import.meta` in browser and tooling. However `import.meta` has been at stage 4 for almost 5 years now: tc39/proposal-import-meta#21 Webback (released in 2020) also has builtin support for `import.meta`, so I would hope the use case for disabling this setting no longer exists. See #9234 and #8729
Issue:
A recent PR resulted in the use of import.meta.url for EXPORT_ES6. However this functionality is currently only at stage 3 (proposal) which means support for this functionality is fairly low which includes eslint, babel, Firefox and Edge all not supporting it currently (all implement at stage 4 or later)
Context:
Looks like there was already a discussion about this and how support isn't quite there yet.
#7137
The text was updated successfully, but these errors were encountered: