When attempting to translate text using the CLI, the command fails with a TypeError indicating that translate is not a function.
Steps to Reproduce
- Install the CLI globally using
npm install -g .
- Run any translation command, for example:
Expected Behavior
The text "hello world" should be translated to Spanish and displayed in a formatted box in the terminal.
Actual Behavior
The command throws the following error:
TypeError: translate is not a function
at C:\Users\FSOS\dev\termTranslate\bin\index.js:56:27
Environment
- Node.js version: v24.11.0
- npm version: v11.6.2
- OS: Windows
- Package version:
@vitalets/google-translate-api v7.0.0
Root Cause
The issue occurs because version 7.x of @vitalets/google-translate-api exports the translate function as the default export, not as a named export. The current import statement attempts to destructure it as a named export, which fails.
Current (incorrect) code:
const { translate } = await import('@vitalets/google-translate-api');
The package actually exports translate as the default export, so it should be imported as:
const { default: translate } = await import('@vitalets/google-translate-api');
Additional Context
This is specific to v7.x of the package. The newer v9.x versions use named exports, so the original syntax would work there, but the current package.json specifies ^7.0.0.
When attempting to translate text using the CLI, the command fails with a TypeError indicating that
translateis not a function.Steps to Reproduce
npm install -g .Expected Behavior
The text "hello world" should be translated to Spanish and displayed in a formatted box in the terminal.
Actual Behavior
The command throws the following error:
Environment
@vitalets/google-translate-apiv7.0.0Root Cause
The issue occurs because version 7.x of
@vitalets/google-translate-apiexports thetranslatefunction as the default export, not as a named export. The current import statement attempts to destructure it as a named export, which fails.Current (incorrect) code:
The package actually exports
translateas the default export, so it should be imported as:Additional Context
This is specific to v7.x of the package. The newer v9.x versions use named exports, so the original syntax would work there, but the current
package.jsonspecifies^7.0.0.