Skip to content

Invalid ES module, internal SyntaxError, error text could use more context #35245

@josh-hemphill

Description

@josh-hemphill
  • Version: v14.11.0
  • Platform: Win10 64bit
  • Subsystem: internal/modules/esm/translators.js:117:18

What steps will reproduce the bug?

While other async operations are happening, load a malformed ES module

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

Consistently, in an ES module project, it seems to appear with lots of async operations including some that are using sockets.

What is the expected behavior?

Error: unexpected character at ...

What do you see instead?

(node:26584) UnhandledPromiseRejectionWarning: SyntaxError: Missing initializer in destructuring declaration
    at Loader.moduleStrategy (internal/modules/esm/translators.js:117:18)
    at Loader.moduleStrategy (internal/modules/esm/translators.js:117:18)
    at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
    at processPromiseRejections (internal/process/promises.js:247:11)
    at processTicksAndRejections (internal/process/task_queues.js:94:32)

Additional information

Easy recreation:

// Malformed Module testImport.js
const {
	general: { getLocal },
} from '#utils');

// imported asynchronously
import('./testImport.js').catch(err => console.log(err))

Results in

SyntaxError: Missing initializer in destructuring declaration
    at Loader.moduleStrategy (internal/modules/esm/translators.js:117:18)
    at async link (internal/modules/esm/module_job.js:42:21)

In which there's no helpful information about the locations/modules involved

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions