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

[sc-66697] Replace node-fetch with nodejs fetch #145

Merged

Conversation

akiradev
Copy link
Contributor

@akiradev akiradev commented Jan 9, 2025

Clients have reported that the SDK cannot be used in CommonJS projects. This is due to node-fetch@3 being an ESM only module.

With Node v18

/adzerk-management-sdk-js/lib/clientFactory.js:56
var node_fetch_1 = __importDefault(require("node-fetch"));
                                   ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /adzerk-management-sdk-js/node_modules/node-fetch/src/index.js from /adzerk-management-sdk-js/lib/clientFactory.js not supported.
Instead change the require of index.js in /adzerk-management-sdk-js/lib/clientFactory.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/adzerk-management-sdk-js/lib/clientFactory.js:56:36)
    at Object.<anonymous> (/adzerk-management-sdk-js/lib/index.js:114:23)
    at Object.<anonymous> (/js-sdk-client/index.js:1:14) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.18.2

With Node v20

/adzerk-management-sdk-js/lib/clientFactory.js:56
var node_fetch_1 = __importDefault(require("node-fetch"));
                                   ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /adzerk-management-sdk-js/node_modules/node-fetch/src/index.js from /adzerk-management-sdk-js/lib/clientFactory.js not supported.
Instead change the require of index.js in /adzerk-management-sdk-js/lib/clientFactory.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/adzerk-management-sdk-js/lib/clientFactory.js:56:36) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v20.16.0

There are workarounds suggested by the maintainers of node-fetch for use with CommonJS, however our use is minimal, therefore we can replace it with NodeJS's fetch which was made GA in v18.

Tested using https://github.com/adzerk/adzerk-management-sdk-integration-tests pointing to a local copy of the SDK.

Copy link
Contributor

@honeycomb-cheesecake honeycomb-cheesecake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@akiradev akiradev merged commit eba19ff into master Jan 9, 2025
4 checks passed
@akiradev akiradev deleted the akirasato/sc-66697/investigate-management-js-sdk-issue-with branch January 9, 2025 15:49
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

Successfully merging this pull request may close these issues.

2 participants