Skip to content

ERR_INTERNAL_ASSERTION with require(esm) #55500

Closed

Description

@nicolo-ribaudo

Version

23.0.0

Platform

Darwin Nics-MacBook-Air.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:16:46 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T8112 arm64

Subsystem

No response

What steps will reproduce the bug?

EDIT: See in #55500 (comment) for a minimal reproduction

How often does it reproduce? Is there a required condition?

I don't have a minimal reproduction

What is the expected behavior? Why is that the expected behavior?

To not tell me to open a bug report :P

What do you see instead?

(node:69972) ExperimentalWarning: Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/assert:11
    throw new ERR_INTERNAL_ASSERTION(message);
          ^

Error [ERR_INTERNAL_ASSERTION]: [BABEL]: A require()-d module that is imported again must be evaluated. Status = 2
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues
 (While processing: /Users/nic/Documents/dev/github.com/babel/babel/packages/babel-core/test/fixtures/async/plugin-mjs-tla-native/plugin.js)
    at assert (node:internal/assert:11:11)
    at ModuleJobSync.run (node:internal/modules/esm/module_job:358:5)
    at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:543:42)
    at async loadMjsFromPath (file:///Users/nic/Documents/dev/github.com/babel/babel/packages/babel-core/lib/config/files/module-types.js:45:12) {
  code: 'ERR_INTERNAL_ASSERTION'
}

Additional information

I don't think I'm using Node.js internals.

cc @joyeecheung

Activity

  1. nicolo-ribaudo commented on Oct 23, 2024

    @nicolo-ribaudo
    ContributorAuthor

    The relevant code is in packages/babel-core/lib/config/files/module-types.js.

    What is going on is that:

    • in loadCodeDefault, we go in the auto .js branch
    • it calls loadCjsDefault, which requires plugin.js
    • that require call throws due to TLA
    • In the catch inside loadCodeDefault, async ??= yield* isAsync() is true to we suppress the error
    • It falls through, and calls loadMjsFromPath in the auto .mjs branch
    • loadMjsFromPath calls import_(url), which calls import(url)

    However, a minimal reproduction of try/catch around require() falling back to import() does not trigger the assertion.

  2. nicolo-ribaudo commented on Oct 23, 2024

    @nicolo-ribaudo
    ContributorAuthor

    Minimal reproduction:

    try {
      require("./file-with-tla.mjs");
    } catch {
      import("./file-with-tla.mjs").then(console.log, console.error);
    }
  3. added
    esm
    loaders
    confirmed-bug
    on Oct 23, 2024
  4. avivkeller commented on Oct 23, 2024

    @avivkeller
    Member
    // tla.js
    await new Promise(resolve => resolve());
    try {
        require("./tla.js");
    } catch {
        import("./tla.js");
    }
  5. avivkeller commented on Oct 23, 2024

    @avivkeller
    Member

    Failing assertion:

    assert(status === kEvaluated,

  6. joyeecheung commented on Oct 23, 2024

    @joyeecheung
    Member

    Thanks for reporting it, fix in #55502

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugesmloaders

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions