1

After following a couple of tutorials online especially this when I run node server.js I get an annoying error and I don't know if there's a fix for it. the project is based on the current version of 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)

my Server.js file

'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`);
});

I'll grateful for any help or resource

TOLULOPE ADETULA
  • 768
  • 1
  • 12
  • 27

0 Answers0