SalesforceCommerceCloud / commerce-sdk

https://salesforcecommercecloud.github.io/commerce-sdk/
BSD 3-Clause "New" or "Revised" License
149 stars 48 forks source link

unable to download nanoid dependency on installing commerce-sdk #368

Closed Sebashish closed 1 year ago

Sebashish commented 2 years ago

Following this step by using node 16 LTS: https://developer.salesforce.com/docs/commerce/commerce-api/guide/api-and-sdk-demo.html

And then got this issue

Screenshot 2022-07-11 at 4 31 49 PM

Using this node version:

Screenshot 2022-07-11 at 4 31 29 PM

This could be because this is listed as a devDependency.

Sebashish commented 2 years ago

@johnboxall @SalesforceCommerceCloud/commerce-cloud-services can you guys please have a look into this. Thanks!

joeluong-sfcc commented 2 years ago

Hi @Sebashish, thanks for raising this issue! We've created an work item in our backlog for this and we'll update you when this issue is resolved and close this out :)

johnboxall commented 1 year ago

Hey folks,

I believe this issue is coming up because we've included nanoid as a devDependancy as opposed to a dependancy:

https://github.com/SalesforceCommerceCloud/commerce-sdk/blob/6874c86162ce63bc74efa18c94a96f2885347b19/package.json#L74

It isn't possible to work around this using npm install nanoid as you end up with a ERR_REQUIRE_ESM error:

const nanoid_1 = require("nanoid");
                 ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/jboxall/git/test-commerce-sdk/node_modules/nanoid/index.js from /Users/jboxall/git/test-commerce-sdk/node_modules/commerce-sdk/dist/helpers/slas.js not supported.
Instead change the require of index.js in /Users/jboxall/git/test-commerce-sdk/node_modules/commerce-sdk/dist/helpers/slas.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/jboxall/git/test-commerce-sdk/node_modules/commerce-sdk/dist/helpers/slas.js:30:18)
    at Object.<anonymous> (/Users/jboxall/git/test-commerce-sdk/node_modules/commerce-sdk/dist/helpers/index.js:52:36)
    at Object.<anonymous> (/Users/jboxall/git/test-commerce-sdk/node_modules/commerce-sdk/dist/index.js:34:19)
    at Object.<anonymous> (/Users/jboxall/git/test-commerce-sdk/index.js:1:28) {
  code: 'ERR_REQUIRE_ESM'
}

As a workaround, you can use commerce-sdk@2.7.1 before helpers that use nanoid were introduced.

git2gus[bot] commented 1 year ago

This issue has been linked to a new work item: W-12184003

joeluong-sfcc commented 1 year ago

Thank you for creating this issue @Sebashish. I am now closing this issue as v2.10.1 of the commerce-sdk resolves this issue