Skip to content

Support named imports in Node.js #78

@johnboxall

Description

@johnboxall

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ackAcknowledged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions