question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AOT Server: Unexpected token import

See original GitHub issue

I’m submitting a …

[x] bug report
[ ] support request
[ ] feature request

Current behavior When serving using ng serve, it works fine. However, when I launch the AOT server, I get this error:

> node dist/server.js

/Users/max/code/test2/node_modules/@ngx-translate/core/index.js:1
(function (exports, require, module, __filename, __dirname) { import { NgModule } from "@angular/core";
                                                              ^^^^^^
SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:78: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.<anonymous> (/Users/max/code/test2/dist/server.js:1212:18)
    at __webpack_require__ (/Users/max/code/test2/dist/server.js:20:30)

Relevant code (full repo for reproduction here):

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { HttpModule, Http } from '@angular/http';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';

import { AppComponent } from './app.component';

export { AppComponent };
export function createTranslateLoader(http: Http) {
  return new TranslateHttpLoader(http, '../assets/i18n/', '.json');
}

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule.withServerTransition({ appId: 'cli-universal-demo' }),
    RouterModule.forRoot([
      { path: '', loadChildren: './home/home.module#HomeModule' },
      { path: 'about', loadChildren: './about/about.module#AboutModule' },
      { path: '**', redirectTo: '', pathMatch: 'full' },
    ]),
    HttpModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [Http]
      }
    })

  ],
  exports: [AppComponent],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Expected/desired behavior

It should compile the same way as ng serve.

Reproduction of the problem I’m using this starter: https://github.com/evertonrobertoauler/cli-universal-demo

Here is the full code I’m using: https://github.com/mmathys/ngxissue

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
yamidvocommented, May 26, 2017

I have the same error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught SyntaxError: Unexpected token import-angular.js
Coding example for the question Webpack + Angular2 AOT: Uncaught SyntaxError: Unexpected token import-angular.js.
Read more >
Webpack + Angular2 AOT - Unexpected token import
in this set-up, how do you transpile the angular2 library being imported from the generated ngfactory files? the current app is a combination...
Read more >
missing file lib/angular2-modal/plugins/bootstrap.js
Error: SyntaxError: Unexpected token < at eval (<anonymous>) at Object.eval ... import { NgModule, ErrorHandler } from '@angular/core'; import ...
Read more >
AOT metadata errors - Angular
bracket notation is not valid in metadata { provide: 'token', ... You'd also get this error if you imported someTemplate from some other...
Read more >
unexpected token 'export' express - You.com | The AI Search ...
I know you said the server is setting Content-Type:application/json ... Node.js - SyntaxError: Unexpected token import (16 answers) Closed 7 months ago ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found