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

require call in ESM build of ts-client #886

Open
DownChapel opened this issue Dec 18, 2024 · 0 comments
Open

require call in ESM build of ts-client #886

DownChapel opened this issue Dec 18, 2024 · 0 comments

Comments

@DownChapel
Copy link

DownChapel commented Dec 18, 2024

We're using SvelteKit (which uses Vite) with the @commercetools/ts-client package. When we run the production version of the website it throws the following error when trying to import the package:

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/app/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

After digging into this a bit the issue appears to be caused by the fact that
the ESM build of ts-client (commercetools-ts-client.esm.js) has a require call in it. E.g. this is how it appears in my node_modules directory:

image

The buffer package appears to allow using the node buffer module in the browser. We're using the package in node (server-side in SvelteKit), so if I remove the require call everything seems to work fine.

We've managed to work around this by using patch-package, but it doesn't seem correct the ESM file has a require call in it instead of an import statement?

The require call looks to have been added here: #835

Thanks!

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

No branches or pull requests

1 participant