-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Native ESM support #3265
Comments
I was hoping to try https://gleam.run/ for writing k6 tests but the internal babel fails to handle the javascript generated by the Gleam compiler. I know this work here and on the roadmap is to remove the need for babel, and I wanted to ask if updating babel was something that could happen sooner and easier to support more Javascript features? (I know zero about this so just assuming that "updating babel" is a thing that would help here and not nonsense :) |
I would recommend using babel (or another tool) to transpile before running in k6 instead. "updating babel" turned out to be complicated and having too many unwanted side effects years ago before dropping it was even close to be viable. So that really isn't on the table, especially given that using another tool before k6 isn't at all that complicated ... I expect gleam already requires transpilation from it's language to JS from what I understand so ... so yeah. Sorry, but we are not trying to "update babel". |
@mstoykov ok, thanks for the explanation! And the very good point that I can just use babel manually. I'll give that a try and move to k6 Slack if I have any trouble -- not sure if it'll need special configuration to output whats supported by k6. |
As part of testing for #3265 it was noticed this isn't uncommon. As there is no way for this to be supported and it will be against how the specification works we prefer to warn users on this at least for a little while.
As part of testing for #3265 it was noticed this isn't uncommon. As there is no way for this to be supported, and it will be against how the specification works we prefer to warn users on this at least for a little while. Co-authored-by: Théo Crevon <oleiade@users.noreply.github.com> Co-authored-by: Ivan <2103732+codebien@users.noreply.github.com>
History
k6 uses a goja as JS VM. Historically goja does not have support for every JS feature, and as such babel has been used for years to supplement that. The way this works is that if goja returns an error while parsing, k6 will try run it through babel (see compatibility mode for more info)
Over the years though all the things babel has been used have been added to goja. Actually goja does now have support for features that the version of babel used by k6 does not have support for:
All of those are currently not really support in k6 as they are not supported by the internal babel which needs to parse them even if it won't transform them. As such using this features with ESM lead to parsing errors.
Solution:
The solution here is to have ESM support in goja and used by k6. This will:
Status:
There is draft PR to add the functionality to goja, with the following high level problems:
It currently doesn't work witheval
- which is definitely blockingThe current way some of the evaluation happens predates async/await support and is not based on it - it is actually 100% a hack. This seems to also be a reason for somewhat more complicated scripts to not work.Connected to the above the current code does predate async/await and does not have support for top-level-await. This is likely blocking due to goja usually adding support for the full set of features around a given concept when that one is introduced. My experience is that this will be super simple once2
is doneThere is an even more WIP/PoC PR to k6 core that is very dated at this point. This should be updated along/after the goja PR is in better shape.
Big parts of the original k6 PR have been backported to the current k6 codebase making this a lot easier, but still some work is required.
The major blocking part is the goja PR which also happens to be more complicated than expected and all the issues there are very interconnected and connected to the internals of goja runtime.
Other connected issues with some context on them
require
is not relative to the file it is written in, but to the one we are evaluating. This is not how commonjs defines it and will be somewhat harder (impossible in some cases?!?) to be implemented once ESM default support is added. Especially if users are mixing ESM and commonjs.The text was updated successfully, but these errors were encountered: