Skip to content

Dynamic imports not supported and application fails to load component #26961

@CarlosTorrecillas

Description

@CarlosTorrecillas

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

Since I have updated to Angular 17 and to the "application" build mode I am not able to use dynamic imports which I am seeing is not supported on ESBuild. If I then move to standard imports I am getting failures when I run the application because I get errors from the the libraries I am importing due to "window is not defined". Essentially I would like to know if there is any kind of workaround for this so that I only load that library - leaflet - when I am running on the browser

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

ERROR ReferenceError: window is not defined
    at eval (c:/git/website/node_modules/leaflet/dist/leaflet-src.js:230:19)
    at eval (c:/git/website/node_modules/leaflet/dist/leaflet-src.js:7:66)
    at node_modules/leaflet/dist/leaflet-src.js (c:/git/website/node_modules/leaflet/dist/leaflet-src.js:10:1)
    at __require2 (C:/git/website/.angular/vite-root/website/chunk-OGTRFHQR.mjs:48:50)
    at eval (c:/git/website/src/app/osm-map/osm-map-wrapper/osm-map-wrapper.component.ts:3:20)
    at async instantiateModule (file:///C:/git/website/node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:50861:9)

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.1.1
Node: 18.13.0
Package Manager: npm 8.19.3
OS: win32 x64

Angular: 17.1.1
... animations, cli, common, compiler, compiler-cli, core
... elements, forms, language-service, platform-browser
... platform-browser-dynamic, platform-server, router, ssr

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1701.1
@angular-devkit/build-angular   17.1.1
@angular-devkit/core            17.1.1
@angular-devkit/schematics      17.1.1
@schematics/angular             17.1.1
rxjs                            7.8.1
typescript                      5.3.3
zone.js                         0.14.3

Anything else?

No response

Metadata

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