Angular Universal服务器捆绑包无法正常工作

时间:2017-12-13 21:59:34

标签: javascript node.js angular angular-universal

在我关注了几个教程,特别是this  运行节点server.js我收到一个恼人的错误,我不知道是否有修复它。 该项目基于当前版本的Angular cli



C:\projects\NoddlesHub>node server.js
C:\projects\NoddlesHub\node_modules\@ng-bootstrap\ng-bootstrap\alert\alert.js:1
(function (exports, require, module, __filename, __dirname) { import { Component, In
put, Output, EventEmitter, ChangeDetectionStrategy, } from '@angular/core';
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.2RxQ (C:\projects\NoddlesHub\dist-server\main.bundle.js:1:23175)




我的Server.js文件



'use strict';

/* Server specific version of Zone.js */
require('zone.js/dist/zone-node');

const express = require('express');
const ngUniversal = require('@nguniversal/express-engine');

/* The server bundle is loaded here, it's why you don't want a changing hash in it */
const appServer = require('./dist-server/main.bundle');

/* Server-side rendering */
function angularRouter(req, res) {

  /* Server-side rendering */
  res.render('index', { req, res });

}

const app = express();

/* Root route before static files, or it will serve a static index.html, without pre-rendering */
app.get('/', angularRouter);

/* Serve the static files generated by the CLI (index.html, CSS? JS, assets...) */
app.use(express.static(`${__dirname}/dist`));

/* Configure Angular Express engine */
app.engine('html', ngUniversal.ngExpressEngine({
  bootstrap: appServer.AppServerModuleNgFactory
}));
app.set('view engine', 'html');
app.set('views', 'dist');

/* Direct all routes to index.html, where Angular will take care of routing */
app.get('*', angularRouter);

app.listen(3000, () => {
  console.log(`Listening on http://localhost:3000`);
});




我会感激任何帮助或资源

0 个答案:

没有答案