Future Web
Future Web

Reputation: 111

Angular universal unexpected token { on npm run start:ssr

I am using angular universal and I build my page with : npm run build:ssr with 0 errors. Then I run : npm run serve:ssr and get this error :

\node_modules\ngx-select-dropdown\dist\components\ngx-select-dropdown-component\ngx-select-dropdown.component.js:9

     (ngx-select-dropdown)    import { Component, Input, EventEmitter, Output, HostListener, ViewChildren... 
                                     ^
        SyntaxError: Unexpected token {

It seems that ngx-select-dropdown is causing this error. How do I fix this error so I could run ssr ?

Tsconfig :

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

Upvotes: 0

Views: 307

Answers (1)

Hassen Fadhlaoui
Hassen Fadhlaoui

Reputation: 187

In your webpack.server.config.js file try to add the externals config

const nodeExternals = require('webpack-node-externals');
module.exports = {
...
  target: 'node',
  externals: [nodeExternals({
    // this WILL include
    whitelist: [
        /^ngx-bootstrap/,
        /^ngx-select-dropdown/
    ]
  })],
  resolve: {
    extensions: ['.ts', '.js']
  },
...

Upvotes: 1

Related Questions