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

TypeScript example fails to compile #281

Open
dandv opened this issue Jul 5, 2024 · 1 comment
Open

TypeScript example fails to compile #281

dandv opened this issue Jul 5, 2024 · 1 comment

Comments

@dandv
Copy link

dandv commented Jul 5, 2024

Out of the box, the TypeScript example at fails to compile:

node --loader=ts-node/esm index.ts

(node:20) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
file:///home/projects/stackblitz-starters-bkpyr8/index.ts:2
import { Client } from 'node-mailjet';
         ^^^^^^
SyntaxError: Named export 'Client' not found. The requested module 'node-mailjet' 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 'node-mailjet';
const { Client } = pkg;

    at _instantiate (node:internal/modules/esm/module_job:155:1617)

Node.js 18.20.3

Online demo: https://stackblitz.com/edit/stackblitz-starters-bkpyr8?file=index.ts&view=editor

PS: is this module maintained any more? There hasn't been any activity since November.

@chyzwar
Copy link

chyzwar commented Sep 18, 2024

Same problem, Issue is where node.js project use ESM and import mailjet client using named export.
We use following workaround

import type { Client } from "node-mailjet";
import Mailjet from "node-mailjet";

    // @see https://github.com/mailjet/mailjet-apiv3-nodejs/issues/281
    // @ts-expect-error Problem in library export and commonjs
    this.client = new Mailjet({
      apiKey,
      apiSecret,
      config: {
        version: "v3.1",
      },
    }) as Client;

and in tsconfig.json

"allowSyntheticDefaultImports": true

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