Skip to content

Load v2 addons that have no main file - #11077

Draft
NullVoxPopuli wants to merge 3 commits into
masterfrom
nvp/v2-addons-without-main
Draft

NullVoxPopuli wants to merge 3 commits into
masterfrom
nvp/v2-addons-without-main

Conversation

@NullVoxPopuli

@NullVoxPopuli NullVoxPopuli commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11076

ember-cli now loads a v2 addon that has no main file (such as addon-main.cjs), instead of throwing missing its addon main file.

Why

A v2 addon in a Vite / Embroider app does not use addon-main.cjs.
Today a library still has to ship one, only so that commands such as ember generate can load it.
For "type": "module" libraries, that one file is the only CommonJS left.

Changes

  • PackageInfo#isV2Addon() checks ember-addon.version === 2.
  • If a v2 addon has no main file (no ember-addon.main, top-level main, or index.js), PackageInfoCache does not record emberAddonMainMissing.
    It still sets addonMainPath at the default location, so the addon's root is its package directory.
  • _getAddonEntryPoint() returns { name } for those addons, so ember-cli builds a plain Addon with no hooks.
  • v1 addons without a main file still report the error.

What ember-cli still reads

ember-cli runs no code from a v2 addon with no main file.
It still reads these:

  • From package.json: name, keywords, dependencies, ember-addon.paths, and ember-addon.before / after.
  • blueprints/, so ember generate still finds the addon's blueprints.
  • config/environment.js, if it exists. The default config() hook requires it.

Classic builds

A classic build gets no build hooks from such an addon: app-js files are not merged, and nothing registers the addon with ember-auto-import.
The default hooks look for the v1 folders (app/, addon/, public/, vendor/) instead, and a v2 addon normally has none of them.
Libraries that support classic builds should keep addon-main.cjs.
This change only removes the requirement for libraries that do not.

Tests

New tests in package-info-cache-test.js:

  • A v2 addon dependency with no main file loads with no errors, and its root is its package directory.
  • A v2 addon project with no main file can run initializeAddons().
  • A v1 addon with no main file still reports emberAddonMainMissing.

Without the fix, these 3 tests fail.

A v2 addon does not need addon-main.cjs outside of classic builds.
ember-cli threw "missing its addon main file" for these addons, so
commands such as `ember generate` failed.

When a v2 addon has no main file, load it as a plain addon rooted at
its package directory.
v1 addons still report the missing main file.

Fixes #11076

Co-Authored-By: Claude Opus 5.5 <[email protected]>
NullVoxPopuli and others added 2 commits October 28, 2026 14:38
A v2 addon's top-level `main` points at code for the browser.
ember-cli fell back to it when `ember-addon.main` was missing, and ran that code in Node.
The browser code then failed to import packages that only exist in the app build.

For v2 addons, only `ember-addon.main` names a file for ember-cli.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This reverts commit 8f6f4e0.

ember-source is a v2 addon whose ember-cli hooks are in its top-level `main` (`lib/index.cjs`).
It has no `ember-addon.main`, so ignoring `main` skipped its hooks, and classic builds lost `@ember/application`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@NullVoxPopuli
NullVoxPopuli marked this pull request as draft November 3, 2026 16:52
@NullVoxPopuli

Copy link
Copy Markdown
Contributor Author

Needs answers:

  • do v2 addons with no addon-main show up in the addons list?
  • do v2 addons with no addon-main still have app-tree merge contributions
  • are v2 addons with no addon-main still able to provide public assets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v2 addons without a main file (addon-main.cjs) fail to load

2 participants