AOT Server: Unexpected token import
See original GitHub issueI’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
-
ngx-translate version: 6.0.1 (@ngx-translate/core), 0.0.3 (@ngx-translate/http-loader@0.0.3)
-
Angular version: 4.1.1
-
Browser: all
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@yamidvo I fixed it. See here: https://github.com/evertonrobertoauler/cli-universal-demo/issues/14#issuecomment-301125219
I have the same error