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

Cannot import local ES6 modules #198

Closed
ppcano opened this issue May 6, 2017 · 3 comments
Closed

Cannot import local ES6 modules #198

ppcano opened this issue May 6, 2017 · 3 comments
Labels
Milestone

Comments

@ppcano
Copy link
Contributor

ppcano commented May 6, 2017

Using an example from samples/REST_API_testsuite/

cd samples/REST_API_testsuite/
k6 -v run v3_account_login.js
DEBU[0001] Babel: Transformed                            t=357.927232ms
DEBU[0001] Fetching source...                            url="https://common?_k6=1"
DEBU[0001] Fetching source...                            url="https://common"
ERRO[0001] GoError: Get https://common?_k6=1: dial tcp: lookup common: no such host
	at native
	at v3_account_login.js:40:122(62)
@ppcano ppcano added the bug label May 8, 2017
@robingustafsson robingustafsson added this to the May 2017 milestone May 8, 2017
@liclac liclac closed this as completed in f9c6ade May 8, 2017
@ppcano
Copy link
Contributor Author

ppcano commented May 9, 2017

@liclac

  1. importing local modules doesn't look to be fully working.
import { myTrend, options, urlbase, thinktime1, thinktime2 } from "./common.js";

Works!

import { myTrend, options, urlbase, thinktime1, thinktime2 } from "./common";

ERRO[0000] GoError: open /Users/ppcano/dev/go/src/github.com/loadimpact/k6/samples/REST_API_testsuite/common: no such file or directory

You can easily test the k6 example:

cd samples/REST_API_testsuite/
k6 -v run v3_account_login.js
  1. I think, a doc article should be written to detail how modules works. Thoughts?

@ppcano ppcano reopened this May 9, 2017
@ragnarlonn
Copy link

A description of how the new load-file-system works (for both import statements and when specifying scripts to execute on the command line) would be very useful, yeah. If @liclac could write some short bullet points, or pseudo code that describes how it works, I can flesh it out into a proper docs page (and test it, so it works as expected).

@liclac
Copy link
Contributor

liclac commented May 9, 2017

Omitting .js is not supposed to work; we can check if a version with .js exists if we're loading locally, but not from a remote host, so we'd end up with code that works differently depending on where it's loaded from.

Pseudocode:

  1. Resolve relative imports into an absolute path, relative to the calling file.
    • If this is a remote resource trying to load a local one as an absolute path (eg. /etc/passwd), block that. This is allowed from local scripts though.
  2. Does the resolved path start with '/'?
    • Load it as a local file.
  3. Does the path match any known services? (CDNJS, GitHub)
    • Check the corresponding adapter for the real URL and fetch that.
  4. If not:
    • Treat the path as a schemaless https:// URL and fetch it.

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

No branches or pull requests

4 participants