How to use ngx-bootstrap with angular4 with server side rendering

丶灬走出姿态 提交于 2019-12-10 23:35:01

问题


i have installed ngx-bootstrap and using angular-cli 1.0.1 and done universal setup with the help of Roberto Auler's Post.

I have added path of bootstrap file in angular-cli.json styles

 "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "styles.css"
      ],

I am using AlertModule for testing and its throwing error

C:\Users\Praveen\Desktop\Projects\Angular2\universaltest\node_modules\ngx-bootstrap\alert\alert.module.js:1
(function (exports, require, module, __filename, __dirname) { import { CommonModule } from '@angular/common';
                                                              ^^^^^^
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.<anonymous> (C:\Users\Praveen\Desktop\Projects\Angular2\universaltest\dist\ngfactory\src\app\app.server.module.ngfact
ory.ts:17:1)
    at Module._compile (module.js:571:32)
    at Module.m._compile (C:\Users\Praveen\Desktop\Projects\Angular2\universaltest\node_modules\ts-node\src\index.ts:406:23)
    at Module._extensions..js (module.js:580:10)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\Users\Praveen\Desktop\Projects\Angular2\universaltest\node_modul
es\ts-node\src\index.ts:409:12)
    at Module.load (module.js:488:32)

Any input will be appreciated.


回答1:


I sent you a pull request, ts-node does not transpiles the es2015 modules like ngx-bootstrap in node_modules, that's why I used webpack to transpile the code.

https://github.com/ranavc32/SimpleMDE-angular-universal/pull/2/commits/193f4a8c58e01a2b55764532d7e3ca8101d312ec



来源:https://stackoverflow.com/questions/43692755/how-to-use-ngx-bootstrap-with-angular4-with-server-side-rendering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!