Skip to content

[Bug]: No package.json exports defined #303

@simonihmig

Description

@simonihmig

Describe the bug

Not exactly a bug, but I would strongly suggest to provide modern package.json export fields alongside the "legacy" fields like main and types.

I see the two issues here currently:

  1. legacy fields allow you to import from deep paths, which likely was never intended as a "public API" of the package. This for example is technically working, but likely not intended as it exposes the whole internal lib file structure, so any change there would be a breaking one for users of these kind of imports:
import type { ModuleFederationOptions } from '@module-federation/vite/lib/utils/normalizeModuleFederationOptions';
  1. The package is defined as type: 'module', but the ESM build (lib/index.esm.js) is not even referenced in the package.json, thus not being used anywhere AFAICT. Instead main points to the CJS build (lib/index.cjs), which defies the purpose of type: 'module'. Or do I miss something?

I would suggest to use explicit export fields, pointing to CJS, ESM and d.ts outputs, but denying any imports other than from the index modules.

Side node: as visible in the example above, we had a need to import ModuleFederationOptions type, but with the proposed changes we wouldn't be able to import than from the deep path, so re-exporting this from index would be helpful also!

Happy to provide a PR if you agree on these changes!

Version

6.2.7

Reproduction

n/a

Relevant log output

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions