Skip to content

fix: incorrect identifier of import binding for module externals#20107

Merged
alexander-akait merged 1 commit intomainfrom
fix-external-esm
Nov 11, 2025
Merged

fix: incorrect identifier of import binding for module externals#20107
alexander-akait merged 1 commit intomainfrom
fix-external-esm

Conversation

@hai-x
Copy link
Copy Markdown
Member

@hai-x hai-x commented Nov 8, 2025

Summary

What kind of change does this PR introduce?

Fixes part of #20088. We need to ensure consistent binding names.

We now construct the import binding name using the module identifier and export name, resolving the binding name conflict issue described in #19867. As a result, recording chunkUsedNames and the binding usage counter is no longer necessary.

cc @xiaoxiaojx

Did you add tests for your changes?

Yes

Does this PR introduce a breaking change?

No

If relevant, what needs to be documented once your changes are merged or what have you already documented?

No

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 8, 2025

This PR is packaged and the instant preview is available (141fd11).

Install it locally:

  • npm
npm i -D https://pkg.pr.new/webpack@141fd11
  • yarn
yarn add -D https://pkg.pr.new/webpack@141fd11
  • pnpm
pnpm add -D https://pkg.pr.new/webpack@141fd11

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Nov 8, 2025

CodSpeed Performance Report

Merging #20107 will not alter performance

Comparing fix-external-esm (141fd11) with main (cbac96e)

Summary

✅ 69 untouched

@arikorn
Copy link
Copy Markdown

arikorn commented Nov 8, 2025

Thank you @hai-x you are beyond awesome!!!

Edit: The code runs properly with this PR! My mistake for upgrading webpack in the wrong yarn workspace. (Companion uses nested workspaces and I wasn't paying close enough attention to which one is used for the packaging build...)

You can read or ignore the rest of this up to the final "minor footnote" about the github-actions bot.

I'm afraid this current attempt didn't help. THIS WORKED!
FWIW, the error appears to be related to the combination of external modules and multiple entry points. I suspect so because the code runs when called from one place, but not from another. For example, in the following output I've added a bunch of console.log calls around the call to new Canvas() and its callers. If I call it via getCachedRenderOrGeneratePlaceholder directly if fails in the 'production'-packaged code; if called via drawButtonImageUnwrapped, which is executed in a separate thread in the standard code, it succeeds:

The test-code: (drawButtonImageUnwrapped is called later in a renderer thread)

console.log('test GraphicsController at init')
try {
 this.getCachedRenderOrGeneratePlaceholder(location)
 //GraphicsRenderer.drawButtonImageUnwrapped(this.#drawOptions, buttonStyle, location, undefined)
} catch (e) {
	this.#logger.error(`Attempt failed for ${JSON.stringify(location)}! ` + e )
}

the result:

test GraphicsController at init
getCachedRenderOrGeneratePlaceholder: {"pageNumber":1,"column":0,"row":1}
Creating new Image object.
About to create canvas
 error Graphics/Controller Attempt failed for {"pageNumber":1,"column":0,"row":1}! ReferenceError: __WEBPACK_EXTERNAL_MODULE__napi_rs_canvas_a643e547_Canvas___0 is not defined

drawButtonImageUnwrapped new Image for {"pageNumber":1,"column":0,"row":1}
About to create canvas
Created canvas
Got context2d
Set oversampling
drawButtonImageUnwrapped new Image done for {"pageNumber":1,"column":0,"row":1}

In fact calling drawButtonImageUnwrapped itself in my inserted test-code (commented out above), will crash in the production-packaged code but not when called from the renderer thread. For some reason, though, my try-catch isn't being honored in that case, so the output isn't as nice. (And again, everything runs fine in unpackaged or dev-packaged code.)

Minor footnote: FWIW, if you have control of the github-actions bot output, the correct syntax for yarn (probably yarn "2", i.e. 4.10) is:

yarn add -D webpack@https://pkg.pr.new/webpack@f4b3582

(i.e. needs 'webpack@' before the URL)

@arikorn
Copy link
Copy Markdown

arikorn commented Nov 8, 2025

Oh wait! It does work! I upgraded the wrong yarn workspace.

On that note, webpack from this PR identifies itself as 5.102.1 during run time. It might be useful, if possible, to add something to differentiate it from the release version, so we're certain I'm running the correct version... I'll have to be more vigilant in the future too...

@hai-x hai-x marked this pull request as ready for review November 10, 2025 19:49
@alexander-akait
Copy link
Copy Markdown
Member

@hai-x I am fine with this changes, let's wait @xiaoboost review too

@xiaoboost
Copy link
Copy Markdown
Contributor

i think it probably wanted to tag “xiaoxiaojx“, not me(xiaoboost)?

@xiaoxiaojx
Copy link
Copy Markdown
Member

i think it probably wanted to tag “xiaoxiaojx“, not me(xiaoboost)?

Yeah, Sorry to bother you. 😂

@alexander-akait alexander-akait merged commit 7e7af04 into main Nov 11, 2025
52 checks passed
@alexander-akait alexander-akait deleted the fix-external-esm branch November 11, 2025 15:04
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.

5 participants