Skip to content

fix: add fullySpecified: false to webpack config for v2 addon index.js resolution - #682

Closed
lifeart wants to merge 1 commit into
embroider-build:mainfrom
lifeart:fix-index-imports-in-parent-apps
Closed

fix: add fullySpecified: false to webpack config for v2 addon index.js resolution#682
lifeart wants to merge 1 commit into
embroider-build:mainfrom
lifeart:fix-index-imports-in-parent-apps

Conversation

@lifeart

@lifeart lifeart commented Jan 20, 2026

Copy link
Copy Markdown

Adds fullySpecified: false to webpack's module rules to support v2 addons that use "type": "module" in their package.json with directory imports.

Problem

When a v2 addon uses "type": "module" in package.json and has internal imports without explicit /index.js paths, webpack 5's strict ESM resolution fails to resolve them.

Error Case (before fix)

  Addon structure:                                                                                                                                                                             
  my-addon/                                                                                                                                                                                    
  ├── package.json          # { "type": "module", "exports": { ".": "./dist/index.js", "./*": "./dist/*" } }                                                                                   
  └── dist/                                                                                                                                                                                    
      ├── index.js          # import { foo } from './components/my-component'                                                                                                                  
      └── components/                                                                                                                                                                          
          └── my-component/                                                                                                                                                                    
              └── index.js  # export function foo() { ... }                                                                                                                                    

Error message:

  Module not found: Error: Can't resolve './components/my-component'                                                                                                                           

BREAKING CHANGE: The request './components/my-component' failed to resolve only because
it was resolved as fully specified (probably because the origin is strict EcmaScript Module,
e.g. a module with javascript mimetype, a '.mjs' file, or a '.js' file where the
package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

Success Case (after fix)

The same addon structure now works correctly:

  • import { foo } from './components/my-component' resolves to ./components/my-component/index.js
  • Directory imports within ESM packages work without requiring explicit /index.js suffix

Solution

Add a webpack module rule that disables strict ESM resolution for .js files:

{                                                                                                                                                                                            
  test: /\.js$/,                                                                                                                                                                             
  resolve: {                                                                                                                                                                                 
    fullySpecified: false,                                                                                                                                                                   
  },                                                                                                                                                                                         
},                                                                                                                                                                                           

@lifeart

lifeart commented Jan 21, 2026

Copy link
Copy Markdown
Author

Closing this PR because it's seems cover same issue we had to fix but from another side:

The fullySpecified: false fix:

  • Allows webpack to resolve directory imports like ./components/my-component -> ./components/my-component/index.js
  • Fixes webpack's strict ESM resolution for type: "module" packages

Our current fix (#683):

  • Ensures the AMD dependency lookup uses resolvedSpecifier (what webpack actually resolved to) instead of requestedSpecifier (what was written in the import)

They're complementary:

Import: 'addon-with-index/components/my-component'
->
fullySpecified: false
->
Webpack resolves to: 'addon-with-index/components/my-component/index.js'
->
Our fix ensures EAI_DISCOVERED_EXTERNALS uses this resolved path
->
AMD dependency lookup succeeds

Without both fixes:

  1. Without fullySpecified: false -> webpack can't resolve directory imports at all
  2. Without our fix -> even if webpack resolves correctly, AMD lookup uses wrong specifier and can't find dependencies

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

Successfully merging this pull request may close these issues.

1 participant