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

Error introduced in v1.0.25: ESM Import Issues #7

Closed
BenJackGill opened this issue Feb 4, 2025 · 2 comments
Closed

Error introduced in v1.0.25: ESM Import Issues #7

BenJackGill opened this issue Feb 4, 2025 · 2 comments

Comments

@BenJackGill
Copy link

BenJackGill commented Feb 4, 2025

Description

Version 1.0.25 introduced a breaking change that affects ESM imports. When using the package in an ESM context (with "type": "module" in package.json), the following error occurs during runtime:

import { SerpApi, SerpTaskRequestInfo, DataforseoLabsApi, DataforseoLabsGoogleHistoricalSearchVolumeLiveRequestInfo, DataforseoLabsGoogleKeywordIdeasLiveRequestInfo, DataforseoLabsGoogleKeywordsForSiteLiveRequestInfo, BusinessDataApi, BusinessDataGoogleMyBusinessInfoLiveTaskInfo, AppendixApi, AppendixWebhookResendRequestInfo } from 'dataforseo-client';
                  ^^^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'SerpTaskRequestInfo' not found. The requested module 'dataforseo-client' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'dataforseo-client';
const { SerpApi, SerpTaskRequestInfo, DataforseoLabsApi, DataforseoLabsGoogleHistoricalSearchVolumeLiveRequestInfo, DataforseoLabsGoogleKeywordIdeasLiveRequestInfo, DataforseoLabsGoogleKeywordsForSiteLiveRequestInfo, BusinessDataApi, BusinessDataGoogleMyBusinessInfoLiveTaskInfo, AppendixApi, AppendixWebhookResendRequestInfo } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:431:15)
    at async loadModule (/Users/BenJackGill/Dev/seoturbo/node_modules/.pnpm/[email protected][email protected][email protected]_/node_modules/firebase-functions/lib/runtime/loader.js:48:20)
    at async loadStack (/Users/BenJackGill/Dev/seoturbo/node_modules/.pnpm/[email protected][email protected][email protected]_/node_modules/firebase-functions/lib/runtime/loader.js:157:17)
    at async /Users/BenJackGill/Dev/seoturbo/node_modules/.pnpm/[email protected][email protected][email protected]_/node_modules/firebase-functions/lib/bin/firebase-functions.js:56:27

The suggested fix in the error message does not work either because ISerpTaskRequestInfo and SerpTaskRequestInfo are not exported.

Were they removed on purpose or by accident? Maybe they got renamed? I am unsure what to use in their place.

Environment

  • Node.js version: 20
  • dataforseo-client version: 1.0.25
  • Project type: ESM ("type": "module" in package.json)

Steps to Reproduce

  1. Set up a Node.js project with "type": "module" in package.json
  2. Install [email protected] (or the current [email protected])
  3. Try to import named exports directly:

Expected Behavior

Named imports should work as they did in version 1.0.24 and below.

Current Behavior

The module fails to load with an export error.

@lVics
Copy link
Collaborator

lVics commented Feb 5, 2025

Hi, yes, in versions 1.0.25+ we decided to make each request model unique (for each endpoint) to avoid a situation where some endpoint with a common request model would need to add a new parameter that is not required for other endpoints with the same common model. You can find the model you need by exploring the endpoint you are using, or by searching the documentation

@lVics lVics closed this as completed Feb 6, 2025
@BenJackGill
Copy link
Author

BenJackGill commented Feb 6, 2025

Ok thanks. That makes sense, and preferred by myself also. More declarative approach.

If you have the capability it might be good to include some small release notes so we know what changes are made on each version.

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

No branches or pull requests

2 participants