cookies icon indicating copy to clipboard operation
cookies copied to clipboard

Unexpected token import when running server.js

Open ilDon opened this issue 6 years ago • 2 comments

I've followed all steps of the guide, but I get the following error when running node server.js:

../node_modules/@ngx-utils/cookies/src/cookies-options.service.js:1
(function (exports, require, module, __filename, __dirname) { import { Inject, Injectable, InjectionToken, Injector } from '@angular/core';
                                                          ^^^^^^

SyntaxError: Unexpected token import

I've also added @ngx-utile/cookies umd file to scripts in the .angular-cli.json file, as follows, but it did not work:

"scripts": [
  "../node_modules/@ngx-utils/cookies/bundles/cookies.umd.js"
 ]

Am I missing something?

ilDon avatar Apr 23 '18 12:04 ilDon

It's certainly late but perhaps it can help someone. You need to downgrade the code to ES5.

add this in you dev-dependencies : "babel": "^6.23.0", "babel-cli": "^6.26.0", "babel-preset-es2015": "^6.24.1",

and simply run this npm script :

"babel:ngx-utils": "node node_modules/babel-cli/bin/babel.js node_modules/@ngx-utils/cookies --out-dir node_modules/@ngx-utils/cookies --presets es2015",

xrobert35 avatar Aug 20 '18 21:08 xrobert35

Getting same error with latest angular versions.

Any news about it?

[EDIT]

After many tests, i installed latest zip angular-universal official example project and all run perfect.

https://angular.io/generated/zips/universal/universal.zip

So i recommend to start with this angular-universal project for new projects.

segux avatar Feb 25 '19 16:02 segux