Skip to content
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

k6 path resolution doesn't work from CWD when running from stdin #1462

Closed
na-- opened this issue May 22, 2020 · 5 comments · Fixed by #3676
Closed

k6 path resolution doesn't work from CWD when running from stdin #1462

na-- opened this issue May 22, 2020 · 5 comments · Fixed by #3676

Comments

@na--
Copy link
Member

na-- commented May 22, 2020

Environment

  • k6 version: 0.26.2
  • OS and version: Linux (though this probably happens on other OSes as well)

Expected Behavior

If I have the following as test.js:

export var test = 123;

and if I have this as script.js:

import { test } from "./test.js"

export default function (data) {
    console.log(test);
}

And both of these files are in the same folder, I should be able to execute them both by running k6 run ./script.js and k6 run - <./script.js, and get 123 printed either way.

Actual Behavior

Instead, only the first command works. The second gives the following error:

GoError: The moduleSpecifier "file:///test.js" couldn't be found on local disk. Make sure that you've specified the right path to the file. If you're running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they're accessible by k6 from inside of the container, see https://docs.k6.io/v1.0/docs/modules#section-using-local-modules-with-docker. 

For some reason, it's looking at the import file in the root folder.

@na-- na-- added bug evaluation needed proposal needs to be validated or tested before fully implementing it in k6 labels May 22, 2020
@trathborne
Copy link

Neither work for me! Had to specify full paths in my test script.

@na-- na-- added good first issue and removed evaluation needed proposal needs to be validated or tested before fully implementing it in k6 labels Nov 22, 2021
@ecmyilmz
Copy link

I had the same issue but a little bit different, I had forgotten lastfix ".js", I mean I imported
import { test } from "./test", Maybe you can try to delete ".js"

@mstoykov
Copy link
Collaborator

@ecmyilmz this seems like #475 and as written there it's very unlikely that k6 will start adding .js to the end of module identifiers just in case that works. It seems that even node (finally) decided to drop this for ESM modules

@IttiS46
Copy link

IttiS46 commented Jan 6, 2022

Neither work for me! Had to specify full paths in my test script.

I have the same issue on mac os Big Sur 11.5.2

@JapuDCret
Copy link

I had the same issue but a little bit different, I had forgotten lastfix ".js", I mean I imported import { test } from "./test", Maybe you can try to delete ".js"

Thank you! I had to change

import { config } from '../environment';

to

import { config } from '../environment.js';

mstoykov added a commit that referenced this issue Apr 5, 2024
Usually the working dir for a given script is set based on it's path.

For test from stdin that path is file:///- so it is basically the root
folder. With this change this changes to the directory k6 was ran from.

This means when you do `cat script.js | k6 run -` the working dir will
be the same as if you did `k6 run script.js`.

But there is still no way to fix `cat path/to/somewhere/script.js | k6
run -` as k6 can't know where it got it's stdin from.

fixes #1462
mstoykov added a commit that referenced this issue Apr 8, 2024
Usually the working dir for a given script is set based on it's path.

For test from stdin that path is file:///- so it is basically the root
folder. With this change this changes to the directory k6 was ran from.

This means when you do `cat script.js | k6 run -` the working dir will
be the same as if you did `k6 run script.js`.

But there is still no way to fix `cat path/to/somewhere/script.js | k6
run -` as k6 can't know where it got it's stdin from.

fixes #1462
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants