Ngx-bootstrap: Angular Universal: SyntaxError: Unexpected token import

Created on 7 Aug 2017  路  23Comments  路  Source: valor-software/ngx-bootstrap

Update by @valorkin : blocked by Angular-CLI angular/angular-cli#7200

Hi Guys, Thank you for your great work!

I'm trying to make ngx-bootstrap work with Universal but getting this error when trying to run:

 node_modules/ngx-bootstrap/modal/modal-backdrop.component.js:1
(function (exports, require, module, __filename, __dirname) { import { Component, ElementRef, Renderer } from '@angular/core';
                                                              ^^^^^^
SyntaxError: Unexpected token import
    at createScript (vm.js:53:10)
    at Object.runInThisContext (vm.js:95:10)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.IBu+ (/private/var/folders/7w/snfpnc0x7yd302z6rsfs69zc0000gn/T/fbfn_10215rsiZqtRl494A/dist-server/main.a7ad34b20e2d30c271dd.bundle.js:1:146690)

Any suggestions?

blocked comp(modal) env(server)

Most helpful comment

This is why such questions should be on stack overwflow, so ppl can google it

All 23 comments

I am also facing this problem.

Same issue here too

@saoron What version are you using?

This is happening both on 1.8.1 and on the latest beta 2.0.0-beta.3.

One option is to eject the webpack and whitelist ngx-bootstrap. But then that would defeat the purpose of using ang-cli. ngx-translate example

I am using Angular 4 + universal. I followed the steps listed here to build universal code from my angular 4 codebase. On my end, this occurs after I use ang-cli to build my server code and then run node server.js
screen shot 2017-08-20 at 3 36 03 pm

unfortunately, it is ng-cli issue, so we will have to wait for fix
error is complaining about es6 modules style
it means than ngx-bootstap was not compiled by cli

@neilhem thanks for link!

So, according to @Toxicable it would appear that this, indeed, will fall on the libraries, not the cli. See here, and the few subsequent comments: https://github.com/angular/angular-cli/issues/7200#issuecomment-328713190

I have the same problem. As I saw angular universal have problem with modal components. I tried ngx bootstrap modal and angular material modal. both had problem with universal. even with asp .net core universal problem exist. remove all modals component to fix the error

We will publish fix next week, when qa out of vacation.
You can verify fix here: https://ngx-universal.herokuapp.com/modals

I still met this issue in version: 1.9.0

Which version did you fix?

@longhoang2984 angular unniversal support was added in 2.0.0-beta.8

I just upgraded ngx-bootstrap to 2.0.0-beta.8 (confirmed it by checking node modules) But I still get a carousel error
node_modules/ngx-bootstrap/carousel/carousel.component.js:18

import { Component, EventEmitter, Input, NgZone, Output } from angular/core;
^^^^^^

SyntaxError: Unexpected token import

Can someone help me fix this ?

I was explaining in similar issue, nodejs doest support es6 import style, so files should be compiled with webpack or typescript before using in node.
Fully working sample can be found here https://github.com/valor-software/ngx-bootstrap/tree/development/scripts/universal

This is why such questions should be on stack overwflow, so ppl can google it

@abhijithmannath take a look on this thread

solving angular universal issues

@dafabulousteach Could you please let me know how did you solve this issue ?

Thanks !

@b6791 Unfortunately, I never did solve this. But seeing that there has been a new release to ang-cli, there might be a fix. On the other hand, the problem is with ngx-bootstrap itself. Sorry I couldn't help.

@dafabulousteach Anyway no problem thanks for the reply.

Guys I have the same problem any suggestion :

Error:

function (exports, require, module, __filename, __dirname) { export { BsModalRef } from './bs-modal-ref.service';
                                                              ^^^^^^
SyntaxError: Unexpected token export
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)

package.json:

"ngx-bootstrap": "2.0.5", angular version 6.2.3

Installing babel with the 1-7 instruction did not work for me... Do you recommend any troubleshooting steps?
https://github.com/SebastianM/angular-google-maps/issues/1052

Was this page helpful?
0 / 5 - 0 ratings