Skip to content

TypeError: translate is not a function when running translation command #4

@N3VERS4YDIE

Description

@N3VERS4YDIE

When attempting to translate text using the CLI, the command fails with a TypeError indicating that translate is not a function.

Steps to Reproduce

  1. Install the CLI globally using npm install -g .
  2. Run any translation command, for example:
    tran es hello world

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions