运行server.js时出现快速错误

时间:2017-10-14 15:35:58

标签: express angular-cli

我正在按照这些说明启用我的角度应用,使其适合搜索引擎:https://github.com/angular/angular-cli/wiki/stories-universal-rendering

但是当我运行:node server.js时,我收到以下错误:

$ node server.js /generic-skin/node_modules/angulartics2/dist/providers/ga/angulartics2-ga.js:1 (function (exports, require, module, __filename, __dirname) { import { Injectable } from '@angular/core';
                                                              ^^^^^^ SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:73:16)
    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.WRHe (/Users/Development/gambling-tec/skins/generic-skin/dist/server/main.bundle.js:1:220165)
    at n (/skins/generic-skin/dist/server/main.bundle.js:1:211)

我不是100%确定此错误的含义或如何进行错误测试。

非常感谢任何建议。

修改

我的server.js文件

'use strict';

require('zone.js/dist/zone-node');
require('reflect-metadata');

const express = require('express');
const ngUniversal = require('@nguniversal/express-engine');
const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader');

const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist-server/main.bundle');


function angularRouter(req, res) {
  res.render('index', {req, res});
}

const app = express();

app.engine('html', ngUniversal.ngExpressEngine({
  bootstrap: AppServerModuleNgFactory,
  providers: [
    provideModuleMap(LAZY_MODULE_MAP)
  ]
}));
app.set('view engine', 'html');
app.set('views', 'dist');

app.get('/', angularRouter);

app.use(express.static(`${__dirname}/dist`));

app.get('*', angularRouter);

app.listen(3000, () => {
  console.log('Listening on port 3000');
});

0 个答案:

没有答案