You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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!
The text was updated successfully, but these errors were encountered:
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: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 arequire
call in it. E.g. this is how it appears in my node_modules directory: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 therequire
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 arequire
call in it instead of an import statement?The require call looks to have been added here: #835
Thanks!
The text was updated successfully, but these errors were encountered: