Skip to content

Angular should *not* disable Webpack's import.meta.url parsing (for WebAssembly files, at least) #24617

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

Actually, Angular should just make up its h*cking mind (see #24616).

Currently, its mysterious and ephemeral built-in webpack configuration disables module.parser.javascript.url, so assets imported with new URL(..., import.meta.url) do not get packaged by default.

Okay, that's fine, if you're into that kind of thing, but at the same time it keeps module.parser.java.importmeta enabled, leading webpack to output entirely useless file:// URLs instead of doing any packaging.

End result is that you just can't use any ES6 module (such as anything compiled with Emscripten's EXPORT_ES6 option) that tries to load some possibly really important asset, like, say, a WebAssembly file. You are damned if you do and damned if you don't! If you do what is suggested in #22351 and try to use the assets option, the actually generated code will not reference this asset because import.meta.url got rewritten to some path on your build filesystem.

But if you then disable module.parser.java.importmeta manually in a custom webpack config, then you end up with import.meta.url in the output code, which utterly breaks testing with karma (since karma does not do ES6 modules, because that's like not groovy, man) and of course also any possibility of targeting a non-ES6-aware browser.

This is the opposite of webpack's perfectly good and sane defaults. A reasonable workaround is to create a custom webpack config which enables module.parser.java.url, like this:

module.exports = {
  module: {
    parser: {
      javascript: {
        url: true,
      },
    },
  },
};

Minimal Reproduction

From an Angular app, try to load an ES6 module (like https://www.npmjs.com/package/soundswallower?activeTab=explore) that has an accompanying WASM file, or any kind of asset that is loaded with new URL(..., import.meta.url). The relevant code output by Emscripten is:

 wasmBinaryFile = new URL("soundswallower.web.wasm", import.meta.url).href;

Exception or Error

No response

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