Skip to content

"default" import broken with Vite 8 (Rolldown) due to missing ESM interop (__esModule) #133

Description

@Brezinben

Hello, during migration of vite 8 I encontered, little issue.

Root cause

The package only exposes a CJS build ("main": "out/index.js") with no type: "module",
no exports field, and no "module" field in package.json.

The CJS output does not set __esModule: true on module.exports. This flag is the
standard interop marker used by bundlers (Rollup, Webpack, esbuild…) to indicate that a
CJS module was originally written as ESM and that module.exports.default should be used
as the default export.

Without it, Rolldown's new Consistent CommonJS Interop
(Vite 8) treats module.exports itself as the default export — which is the correct
behavior. However, since module.exports is the whole namespace object (not the class),
instantiating it fails.

Reproduction

// Works in Vite ≤ 7, breaks in Vite 8
import OtaClient from '@crowdin/ota-client';
const client = new OtaClient('hash'); // TypeError: OtaClient is not a constructor

Rolldown doc : https://rolldown.rs/in-depth/bundling-cjs#recommendations-for-library-authors

Workaround (temporary)

export default defineConfig({
  legacy: { inconsistentCjsInterop: true }, // deprecated, will be removed in a future Vite version
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions