Typescript + external deps

(⎈ |prod5.us-east-1:default) ➜  pf-load-testing (master) ✗ npm run start                                                                                                                                                                                                                                                                                                                                                                                         <aws:tm-nonprod-Ops-Techops>

> pf-load-testing@1.0.0 prestart /Users/alexandrelemieux/tm/tm1/pf-load-testing
> npm run build


> pf-load-testing@1.0.0 build /Users/alexandrelemieux/tm/tm1/pf-load-testing
> npx tsc


> pf-load-testing@1.0.0 start /Users/alexandrelemieux/tm/tm1/pf-load-testing
> k6 run build/index.js


          /\      |‾‾|  /‾‾/  /‾/   
     /\  /  \     |  |_/  /  / /    
    /  \/    \    |      |  /  ‾‾\  
   /          \   |  |‾\  \ | (_) | 
  / __________ \  |__|  \__\ \___/ .io

WARN[0001] A url was resolved but it didn't have scheme. This will be deprecated in the future and all remote modules will need to explicitly use `https` as scheme  url=//url-parse
ERRO[0002] GoError: The moduleSpecifier "url-parse" couldn't be retrieved from the resolved url "https://url-parse". Error : "Get https://url-parse: dial tcp: lookup url-parse: no such host" 
  "devDependencies": {
    "@types/k6": "^0.25.0",
    "@types/url-parse": "^1.4.3",
    "typescript": "^3.6.3"
  },
  "dependencies": {
    "url-parse": "^1.4.7"
  }

Hi @piclem, k6 doesn’t support node module resolution or typescript and this is somewhat unlikely to change in both cases.
So you have two options:
You could get your dependencies from inside of node_modules or download them directly, and then import them with their full paths, possibly after browserfing some of them if they don’t run natevily in k6.
You can also try my proof of concept which uses webpack and babel to both do node modules resolution and combine all of the sources into a single file. You can definitely add it to automatically transpile typescript along the way. Please do share how it worked for you and if you automate the typescript transpiling I do take PRs :wink:

1 Like

Yeah i try something like our repo. I’m using webpack to build a bundle for typescript + npm project for now it seems to work like a charm.

1 Like

Related TypeScript Example

1 Like