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

fix: support modern esm and types resolution #48

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

IlyaSemenov
Copy link
Contributor

Currently, the package won't run with vite/rollup which is arguably one of the most (if not the most) popular bundler setup.

First, it would use a CJS build instead of ESM build even in pure ESM ("type": "module") projects. This is because the ESM build is not published in a standard-compliant way.

Then, with CJS build, it will not import sub-deps properly:

function JWTServerToken(apiSecret, jwtOptions = {}) {
    const payload = {
        server: true,
    };
    const opts = Object.assign({ algorithm: 'HS256', noTimestamp: true }, jwtOptions);
    return jwt.sign(payload, apiSecret, opts); // <------- here it will crash
    // because jwt is { default: { sign: ... } }
}

Then, under some circumstances the types won't load with modern Typescript setup ("moduleResolution" set to "Node16" or "Bundler") with this error: ...There are types at '/......./types/index.d.ts', but this result could not be resolved when respecting package.json "exports".ts(7016)

All and all, the project's package.json is missing the exports section which modern packages should have. The PR adds one.

Also, the top-level module property should be removed from package.json as there is no such field officially. It could have been supported privately by some bundlers but now everything supports exports. I kept module in this PR as you may have been relying on it somehow—but please consider removing it.

@szuperaz szuperaz changed the title Support modern esm and types resolution fix: support modern esm and types resolution Aug 28, 2024
@szuperaz szuperaz merged commit 78e3c9f into GetStream:main Aug 28, 2024
1 of 7 checks passed
@szuperaz
Copy link
Collaborator

Thank you for the contribution

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

Successfully merging this pull request may close these issues.

2 participants