0

I am using babel loader and angular linker so i could transpile some library code inside my node_modules.

Here I found example for that but it is for webpack 5 because they use import statements.

https://github.com/angular/angular/blob/c15b8c75fa1bd8115e2dd10221919d03cf55ea24/integration/platform-server/base-config.mjs

When i try to do this

const webpack = require('webpack');
const linkerPlugin = require('@angular/compiler-cli/linker/babel');
module.exports = {
    /**
     * Remove all unused MomentJS locales
     * The problem is described in this article
     * https://medium.jonasbandi.net/angular-cli-and-moment-js-a-recipe-for-disaster-and-how-to-fix-it-163a79180173
     */
    plugins: [
        new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /de|en|fr|it/),
        new webpack.DefinePlugin({
            ngDevMode: true,
        }),
        new webpack.LoaderOptionsPlugin({
            options: {
                rules: [
                    {
                      test: /\.mjs$/,
                      include: /node_modules\/@ng-select\/ng-option-highlight/,
                      use: {
                        loader: 'babel-loader',
                        options: {
                          configFile: false,
                          plugins: [linkerPlugin],
                        }
                      }
                    },
                    {
                        test: /.*\.(js|ts)$/,
                        exclude: /node_modules/,
                        use: [
                            { loader: 'babel-loader' },
                            { loader: '@ngtools/webpack' },
                            { loader: '@angular-devkit/build-optimizer/webpack-loader' },
                        ],
                    },
                ]
            }
        }),
    ],
}

I still get error

The NgModule is part of a library that has been partially compiled.
However, the Angular Linker has not processed the library such that JIT compilation is used as fallback.

Ideally, the library is processed using the Angular Linker to become fully AOT compiled.
Alternatively, the JIT compiler should be loaded by bootstrapping using '@angular/platform-browser-dynamic' or '@angular/platform-server',
or manually provide the compiler with 'import "@angular/compiler";' before bootstrapping.

so I guess that it is not importhing the library inside because the angular linker is not working.

I also tried

plugin: ["@angular/compiler-cli/linker/babel"]

directly and it is not working again

What is my mistake ?

And as a reference here for others it is working like this in angular webpack 4

JIT compiler unavailable after angular update

0 Answers0