Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm: fix esm load bug #25491

Closed
wants to merge 3 commits into from

Conversation

@ZYSzys
Copy link
Member

commented Jan 14, 2019

If module.reflect is undefined, just run into else condition.

Fixes: #25482

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
@guybedford

This comment has been minimized.

Copy link
Contributor

commented Jan 14, 2019

Unfortunately we can't just override the module map - it has to be treated as an immutable map otherwise we can possibly get race conditions in loading / different instances.

The fix here has to be to ensure the onReady function is available as soon as the moduleMap entry is set.

@guybedford

This comment has been minimized.

Copy link
Contributor

commented Jan 14, 2019

(or change the architecture to not need an onReady)

@ZYSzys ZYSzys force-pushed the zys-contribs:fix-esm-bug branch from 3784449 to aa05d89 Jan 14, 2019

@ZYSzys

This comment has been minimized.

Copy link
Member Author

commented Jan 14, 2019

So how should this to be fixed specifically ?Can you please give me some more guides ?

I've changed it like we previously did: https://github.com/nodejs/node/pull/24560/files#diff-76195ce57689942222a27f0dbda6d3b7L641

Sincerely /cc @devsnek who actual implement the refactor in #24560 (comment)

@devsnek

This comment has been minimized.

Copy link
Member

commented Jan 14, 2019

@guybedford

This comment has been minimized.

Copy link
Contributor

commented Jan 14, 2019

One thing to try might be checking if reflect is available once module.modulePromise has resolved. It would be good to get a test case that captures what is happening in #25482 as well.

Thanks @ZYSzys for your efforts here.

@devsnek

This comment has been minimized.

Copy link
Member

commented Jan 14, 2019

the current change passes all tests, so maybe we're on to something?

cc @bmeck for some hopeful insight

@targos targos added the ES Modules label Apr 25, 2019

@guybedford

This comment has been minimized.

Copy link
Contributor

commented May 12, 2019

So the problem here is that the CJS cache injects into the ESM loader so they share the same instances, but in the case where the ESM loader has already loaded the module, the CJS version should not override the existing ESM version.

So the fix is correct.

I've merged the test case from #27443 into this PR, and can confirm it is fully resolved.

Please lets land this soon and backport the patch as well.

@guybedford guybedford referenced this pull request May 12, 2019
3 of 3 tasks complete

@guybedford guybedford added python and removed python labels May 12, 2019

@guybedford guybedford force-pushed the zys-contribs:fix-esm-bug branch from 16966ec to 5a24194 May 12, 2019

@nodejs-github-bot

This comment was marked as outdated.

@Trott
Trott approved these changes May 13, 2019
Copy link
Member

left a comment

LGTM, but I'd prefer we cherry-pick or am in the test to preserve authorship for the contributor who wrote it, unless there's a good reason not to do that.

ZYSzys and others added 3 commits May 13, 2019
test: clearing require cache crashes esm loader
This test shows the regression introduced in v11.4.0: clearing out the
require.cache crashes node when using the `--experimental-modules` flag.
Refs: #25482

@ZYSzys ZYSzys force-pushed the zys-contribs:fix-esm-bug branch from 1ece1c0 to 72bdf65 May 13, 2019

@ZYSzys

This comment has been minimized.

Copy link
Member Author

commented May 13, 2019

@Trott I've cherry-pick the test and will squash the last fixup when landed, is it ok now ?

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment has been minimized.

@guybedford

This comment has been minimized.

Copy link
Contributor

commented May 13, 2019

Thanks @ZYSzys for updating that - of course we should retain the original commit.

@Trott
Trott approved these changes May 13, 2019
ZYSzys added a commit that referenced this pull request May 14, 2019
esm: fix esm load bug
Fixes: #25482

PR-URL: #25491
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
ZYSzys added a commit that referenced this pull request May 14, 2019
test: clearing require cache crashes esm loader
This test shows the regression introduced in v11.4.0: clearing out the
require.cache crashes node when using the `--experimental-modules` flag.
Refs: #25482

PR-URL: #25491
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@ZYSzys

This comment has been minimized.

Copy link
Member Author

commented May 14, 2019

Landed in 523a9fb...ac3b98c

@aduh95 Thanks and congratulate for your first(Oh, it's not your first time 😅, but still congratulate) contribution to Node.js core 🎉.

@ZYSzys ZYSzys closed this May 14, 2019

@ZYSzys ZYSzys deleted the zys-contribs:fix-esm-bug branch May 14, 2019

targos added a commit that referenced this pull request May 14, 2019
esm: fix esm load bug
Fixes: #25482

PR-URL: #25491
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
targos added a commit that referenced this pull request May 14, 2019
test: clearing require cache crashes esm loader
This test shows the regression introduced in v11.4.0: clearing out the
require.cache crashes node when using the `--experimental-modules` flag.
Refs: #25482

PR-URL: #25491
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@BridgeAR BridgeAR referenced this pull request May 21, 2019
4 of 4 tasks complete
@aduh95 aduh95 referenced this pull request May 25, 2019
3 of 3 tasks complete
BethGriggs added a commit that referenced this pull request Jun 6, 2019
esm: fix esm load bug
Fixes: #25482

Backport-PR-URL: #27874
PR-URL: #25491
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BethGriggs added a commit that referenced this pull request Jun 6, 2019
test: clearing require cache crashes esm loader
This test shows the regression introduced in v11.4.0: clearing out the
require.cache crashes node when using the `--experimental-modules` flag.
Refs: #25482

Backport-PR-URL: #27874
PR-URL: #25491
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@BethGriggs BethGriggs referenced this pull request Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.