Skip to content

Dynamic import(): how to ignore an import that’s passed a variable? #574

@iamakulov

Description

@iamakulov

In our codebase, there’re a few cases where we deliberately use a native import() with a variable, like:

for (const moduleName of moduleNames) {
    const evaluationResult = await import(/* webpackIgnore: true */ moduleName)
    this.evaluatedModules[moduleName] = evaluationResult
}

This works in webpack thanks to /* webpackIgnore: true */ (docs). But in ESBuild, this produces a warning like:

xxx/xxx.ts:241:47: warning: This dynamic import will not be bundled because the argument is not a string literal

Is there any way to silence this warning for such import? If this was a string literal, I’d add it into externals, but I can’t do that with a variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions