如何使用带有angular4的ngx-bootstrap与服务器端渲染

时间:2017-04-29 07:00:47

标签: twitter-bootstrap angular serverside-rendering angular-universal ngx-bootstrap

我已经安装了ngx-bootstrap并使用angular-cli 1.0.1并在Roberto Auler's Post的帮助下完成了通用设置。

我在angular-cli.json样式中添加了bootstrap文件的路径

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

我正在使用AlertModule进行测试及其抛出错误

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)

任何意见都将受到赞赏。

1 个答案:

答案 0 :(得分:3)

我发送了一个pull请求,ts-node没有像node_modules中的ngx-bootstrap那样转换es2015模块,这就是我使用webpack来转换代码的原因。

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