Angular 4 + Angular Universal + NGXerrors "Unexpected token import"

Viewed 194

So I have standatd Angular 4, Angular Universal app with using ngxerrors plugin. During running compilation for server I get error

Unexpected token import. (function (exports, require, module, __filename, __dirname) { import { Directive, Input, Inject, HostBinding, forwardRef } from '@angular/core';

/var/www/html/licz_kalorie/client/node_modules/@ultimate/ngxerrors/src/ngxerror.directive.js:1

I understand that node cannot compile import export keywords. I'm looking for solution not only for this particular plugin, but for another plugins in future that uses import.

I googled and found this solution, which uses webpack.config.js

const nodeExternals = require('webpack-node-externals');

module.exports = {
    ...
    target: 'node',
    externals: [nodeExternals({
    whitelist: [
        /^@ultimate\/ngxerrors/
        ]
    })],
    ...
}

But it does not work. How can I resolve this issue?

0 Answers
Related