Angular bazel ts_devserver add polyfills

220 Views Asked by At
ts_devserver(
    name = "devserver",
    additional_root_paths = ["project/src/_"],
    entry_module = "project/src/main.dev",
    port = 4200,
    scripts = [
        "@npm//:node_modules/tslib/tslib.js",
        "@npm//:node_modules/@angular/localize/bundles/localize-init.umd.js",
        "@npm//:node_modules/@angular/common/locales/es-MX.js",
        "@npm//date-fns:date-fns.umd.js",
        "@npm//immutable:immutable.umd.js",
        ":date_fns_locale_umd",
    ],
    serving_path = "/bundle.min.js",
    static_files = [
        "@npm//:node_modules/zone.js/dist/zone.min.js",
        ":global_stylesheet",
        ":asset_injected_index_html",
        "favicon.ico",
        "manifest.json"
    ],
    deps = [
        ":polyfills",
        ":bazel_umd_modules",
        ":src"
        ],
)

I'm getting the following error

Uncaught Error: It looks like your application or one of its dependencies is using i18n.
Angular 9 introduced a global `$localize()` function that needs to be loaded.
Please run `ng add @angular/localize` from the Angular CLI.
(For non-CLI projects, add `import '@angular/localize/init';` to your `polyfills.ts` file.
For server-side rendering applications add the import to your `main.server.ts` file.)
    at _global.$localize (core.umd.js:32815)
    at Object.eval (ng-bootstrap.umd.js:63)
    at Object.execCb (es-MX.ts:78)
    at Module.check (es-MX.ts:78)
    at Module.enable (es-MX.ts:78)
    at Object.enable (es-MX.ts:78)
    at Module.<anonymous> (es-MX.ts:78)
    at es-MX.ts:78
    at each (es-MX.ts:53)
    at Module.enable (es-MX.ts:78)

polyfills.ts is a ts_library()

import '@angular/localize/init';

I don't now why how to init before app starts... In tests I do it by adding //src:polyfills to runtime_deps and localize init in the srcs.

Any ideas?

1

There are 1 best solutions below

0
On

I solved this adding this script to ts_devserver bootstrap

ts_devserver(
    name = "devserver",
    additional_root_paths = ["project/src/_"],
    bootstrap = [
        "@npm//:node_modules/@angular/localize/bundles/localize-init.umd.js",
    ]
)