Skip to content

Untracable error messages from beyond short-circuitted load hooks #163

Open
@bpstrngr

Description

I've been quite lost for a few days not knowing where a SyntaxError was coming from in a module's import graph,
as I'm compiling typescript imports by returning {source:output,shortCircuit:true,format:"module"} from load,
and all I saw was

SyntaxError: Missing initializer in const declaration
    at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:117:18)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:460:14) 

thrown at the entry import of the typescript module graph.

I logged every compiled source code along with the specifier argument before the shortCircuit to spot which file's final modularization was throwing that syntax error.

Since there is no control over what happens beyond the load hook, would it be possible to simply disclose the specifiers in the error messages coming from there, or otherwise figure out a way to catch them somehow after emerging from load hooks with a shortCircuit?

The first one could be easy peasy, for the second the only solution i can imagine is exposing a "modularize" hook where one could customize the interpretation of the source code with the "vm" module. Which wouldn't be half bad in itself, but also one doesn't exclude the other either (more informative logging in the default modularization "hook", wether it ever gets exposed as "nextModularize" or not).

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions