SalesforceCommerceCloud / commerce-sdk-isomorphic

Browser & Node.js JavaScript client for B2C Commerce API
https://salesforcecommercecloud.github.io/commerce-sdk-isomorphic/
BSD 3-Clause "New" or "Revised" License
43 stars 21 forks source link

Support named imports in Node.js #78

Open johnboxall opened 2 years ago

johnboxall commented 2 years ago

Currently, the SDK doesn't support named imports when running in a Node.js environment:

// Doesn't work!
import { ShopperLogin } from "commerce-sdk-isomorphic";

// Have to do this instead:
import capi from "commerce-sdk-isomorphic";
const { ShopperLogin } = capi;

It would be nice if named imports worked 😁

Steps to reproduce:

mkdir test-commerce-isomorphic-sdk-named-imports
cd test-commerce-isomorphic-sdk-named-imports
npm init -y
npm i commerce-sdk-isomorphic

# Set `"type": "module"` in your `package.json`.

echo 'import { ShopperLogin } from "commerce-sdk-isomorphic";' > index.js
node index.js

Observe the following error:

import { ShopperLogin } from "commerce-sdk-isomorphic";
         ^^^^^^^^^^^^
SyntaxError: Named export 'ShopperLogin' not found. The requested module 'commerce-sdk-isomorphic' is a CommonJS module, which may not support all module.exports as named exports