Skip to content

Angular should disable webpack's import.meta.url parsing by default #24616

Closed as not planned
@dhdaines

Description

@dhdaines

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Previously, it was noticed that when using ES modules (which Angular very much wants you to do), one cannot reference assets using import.meta.url (which is a web standard and really ought to work). See: https://github.com/angular/angular-cli/issues?q=is%3Aissue+import.meta.url+

This issue, which describes the problem well: #22388 was closed bcause it's actually Webpack's fault and Webpack used to unconditionally rewrite import.meta.url to something useless in the absence of a loader. But now we can stop Webpack from doing that, using the parser.javascript.importMeta option: webpack/webpack#15246

... except that to do this in Angular requires a custom webpack configuration.

Since we are not supposed to have webpack-specific configuration in the angular config, it would be nice if the default behaviour of Angular was non-broken. Obviously it would have to be done while conserving the (arguably broken and inconsistent) policy of sometimes using loaders and sometimes not using them.

Minimal Reproduction

See #22388

Exception or Error

Something about not being able to access local content

Your Environment

Angular CLI: 15.1.2
Node: 18.12.1
Package Manager: npm 9.1.3
OS: linux x64

Angular: 15.1.1
... animations, cdk, common, compiler, compiler-cli, core, forms
... localize, material, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1501.2
@angular-devkit/build-angular   15.1.2
@angular-devkit/core            15.1.2
@angular-devkit/schematics      15.1.2
@angular/cli                    15.1.2
@schematics/angular             15.1.2
rxjs                            7.5.7
typescript                      4.8.4
webpack                         5.75.0

Anything else relevant?

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