-
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
Fix require
to be specification compliant in respect to what it resolves relative to
#3534
Comments
Proposed fix:
Open questions:
Likelihood of someone actually hitting this?IMO it is really low. All cases where babel (or any other tool) will transpile ESM code to commonJS will not hit at all. This also can potentially be breaking some third-party library, although it is also a thing I have never noticed. As such I expect we will not hear from users at all on this. Unlike for |
part of #3534 Co-authored-by: Joan López de la Franca Beltran <[email protected]>
I was referenced here from a warning in my CLI, but it seems to not really be related? Save the following as import http from 'k6/http';
import { URL } from "https://jslib.k6.io/url/1.0.0/index.js"
import { sleep } from 'k6';
export const options = {
vus: 1,
duration: '10s',
};
export default function () {
const appUrl = new URL('http://example.com');
http.get(appUrl.toString())
sleep(5);
} Then run it through docker: $ docker run --rm --net=host -i grafana/k6 run - <script.js
time="2024-05-28T11:57:33Z" level=warning msg="The \"wrong\" path (\"file:///\") and the path actually used by k6 (\"file:///home/k6/\") to resolve \"https://jslib.k6.io/url/1.0.0/index.js\" are different. Please report to issue https://github.com/grafana/k6/issues/3534. This will not currently break your script but *WILL* in the future, please report this!!!" |
I'm dynamically including modules that contain the functions for scenarios' "exec" and also running into this. It's not great having my console absolutely trashed with warnings. Any way to shut this up? Edit: I was able to work around by delegating the require to the execution root, passing the path down. |
@Gikkman Sorry about this and thanks for reporting this. The problem doesn't really impact the correctness of your script nor will it ever. But it caught a case where it will report this wrongly and I have fix, but no test for it. So probably will make a PR on monday. @kleijnweb without a script to reproduce this I can't tell you if you will actually be affected by this change or like @Gikkman this was a red herring. But if you are truly affected as the message suggests your script will likely break in few releases when we fix how |
I delegated the require to be done in the "execution root". So either way the path will be correct. |
Brief summary
k6's
require
has always resolved specifiers relative to the current "root of execution" module/script instead of to relative to the script/module the file is in.An example below will help illustrate what "root of execution" is.
This behavior has been around forever and is against the specification for commonJS and is not how dynamic
import
works or to be honest anything else I have come around.The same issue is true for
open
, but:require
specific to limit it scopeopen
is not based on any specificationFor the rest of the issue I might add "Also relevant to
open
" as reminder for this, butopen
is not what we discuss here.This is extracted from #2674 within a more actionable issue
k6 version
all
OS
all
Docker version and image (if applicable)
No response
Steps to reproduce the problem
Have 3 files:
main.js
/A/a.js:
/A/b.js
This should not throw an exception - but it does. As at the time
s()
is executed the "root of the execution" ismain.js
not/A/a.js
and consequently k6 resolves./b.js
based on that and then loading it from disk doesn't find it leading toExpected behaviour
Script runs as expected and there is no exception.
Actual behaviour
The text was updated successfully, but these errors were encountered: