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

Missing type definition for https://jslib.k6.io/k6-utils/1.4.0/index.js import #118

Open
fullheart opened this issue Oct 16, 2024 · 5 comments

Comments

@fullheart
Copy link

After upgrading to latest version (0.13.0) to resolve a bug, I got an other problem:

node_modules/k6-jslib-aws/src/internal/secrets-manager.ts:3:24 - error TS2307: Cannot find module 'https://jslib.k6.io/k6-utils/1.4.0/index.js' or its corresponding type declarations.
    
3 import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js'
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error in node_modules/k6-jslib-aws/src/internal/secrets-manager.ts:3

Versions: k6-jslib-aws v0.13.0, @types/k6 0.54.0

Steps to reproduce

git clone [email protected]:grafana/k6-jslib-aws.git && cd k6-jslib-aws/ && git checkout v0.13.0
npm install --save-dev @types/k6
npx tsc -t es5 src/internal/secrets-manager.ts
@mstoykov
Copy link
Contributor

This repo doesn't build with tsc directly but with webpack. You can look at the documentation. And webpack specifically doesn't look into https:// imports as they are usually not supported. I am not even certain tsc supports remote modules import. Looking at the error it seems like it doesn't do it well.

btw, what are you trying to do? You don't need to compile the module it is already available in jslib.

@fullheart
Copy link
Author

Thanks @mstoykov for you answer.

Our k6 use case
We are load testing our AWS SageMaker endpoints (ML models) with k6. Our project is written in TypeScript (using Vite to compile into JavaScript files). We have built a k6 client to invoke a SageMaker endpoint. These components are used from this repo:

import { AWSConfig, SignatureV4 } from "k6-jslib-aws";
import { AWSClient } from "k6-jslib-aws/src/internal/client";
import { HTTPRequest, SignedHTTPRequest } from "k6-jslib-aws/src/internal/http";

With tsc the CI pipeline validates the .ts files.

We work around this problem for now with this patch (created with patch-package):

diff --git a/node_modules/k6-jslib-aws/src/internal/secrets-manager.ts b/node_modules/k6-jslib-aws/src/internal/secrets-manager.ts
index cd5967f..dc9148c 100644
--- a/node_modules/k6-jslib-aws/src/internal/secrets-manager.ts
+++ b/node_modules/k6-jslib-aws/src/internal/secrets-manager.ts
@@ -1,5 +1,6 @@
 import { JSONArray, JSONObject } from 'k6'
 import http, { RefinedResponse, ResponseType } from 'k6/http'
+// @ts-ignore
 import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js'
 
 import { AWSClient } from './client'

@mstoykov
Copy link
Contributor

@oleiade do we want to get this in our code as well?

@oleiade
Copy link
Member

oleiade commented Oct 21, 2024

Just to confirm my understanding, a fix that would cater to the problem would be to add a // @ts-ignore statement on our import statement of k6-utils in jslib-aws. Is that correct @fullheart ?

@fullheart
Copy link
Author

fullheart commented Oct 22, 2024

Thanks @mstoykov and @oleiade

Yes, adding the // @ts-ignore line would be a solution.

Another solution would be, when you can add a type definition file (d.ts) in the @types/k6 package that contains all function of this utils package. Example:

declare module 'https://jslib.k6.io/k6-utils/1.4.0/index.js' {
    export function uuidv4(): string;
   // TODO: Add all functions of utils package (https://grafana.com/docs/k6/latest/javascript-api/jslib/utils/#utils)
}

I prefer the second solution to having typed utils functions.

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

No branches or pull requests

3 participants