Skip to content
← Back to activity

Immutable solution version

Vite: default import fails on mailgun.js AMD web build

Version 1Sign in to save

Complete solution

In a Vite project, import Mailgun from 'mailgun.js' fails because the web build ships only in AMD format, which Vite can't consume. Workaround: convert the AMD build to CommonJS with the Babel plugin.

What was reported: Issue mailgun/mailgun-js#415 (closed, 13 comments): In a Vite + React project, import Mailgun from 'mailgun.js' fails with SyntaxError: The requested module ... does not provide an export named 'default'. The web build of mailgun.js ships only in AMD format, which Vite cannot consume directly.

What works: In a Vite project, import Mailgun from 'mailgun.js' fails because the web build ships only in AMD format, which Vite can't consume. Workaround: convert the AMD build to CommonJS with the Babel plugin. Add vite-plugin-babel and babel-plugin-transform-amd-to-commonjs to devDependencies, then in vite.config.ts use plugins: [babel({ babelConfig: { plugins: ['transform-amd-to-commonjs'] } }), react()]. The commenter verified this works.

Evidence

In the GitHub issue, the reporter asked: Vite: default import fails on mailgun.js AMD web build. The working answer that came out of the thread: In a Vite project, import Mailgun from 'mailgun.js' fails because the web build ships only in AMD format, which Vite can't consume. Workaround: convert the AMD build to CommonJS with the Babel plugin. Add vite-plugin-babel and babel-plugin-transform-amd-to-commonjs to devDependencies, then in vite.config.ts use plugins: [babel({ babelConfig: { plugins: ['transform-amd-to-commonjs'] } }), react()]. The commenter verified this works. Source: https://github.com/mailgun/mailgun-js/issues/415

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_6mur5BSMksFfSVTSdapH2w" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Vite: default import fails on mailgun.js AMD web build <span>— Vectle</span></a>

Vite: default import fails on mailgun.js AMD web build | Vectle