ng build - Unexpected token import error.
See original GitHub issueI’m submitting a … (check one with “x”)
[x ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request
H:\d\node_modules\@ngx-translate\core\index.js:1
(function (exports, require, module, __filename, __dirname) { import { NgModule
} from "@angular/core";
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
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> (H:\d\dist\ngfactory\src\app\app.server.module.ngfacto
ry.ts:18:1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! d@0.0.0 build: `ts-node src/server.ts`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the d@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ChrisR\AppData\Roaming\npm-cache\_logs\2017-06-26T16_41_10
_806Z-debug.log
app.server.ts
import { NgModule } from '@angular/core';
import { ServerModule } from '@angular/platform-server'
import { AppComponent } from './app.component';
import { AppModule } from './app.module';
// TRANSLATE
import { TranslateModule, TranslateLoader, TranslateService } from '@ngx-translate/core';
import { translateLoaderFactory } from './core/services/translate.service';
@NgModule({
imports: [
ServerModule,
AppModule,
// TRANSLATE
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: translateLoaderFactory
}
})
],
bootstrap: [ AppComponent ]
})
export class AppServerModule {}
server.ts
import 'reflect-metadata';
import 'zone.js/dist/zone-node';
import { platformServer, renderModuleFactory } from '@angular/platform-server'
import { enableProdMode } from '@angular/core'
import { AppServerModuleNgFactory } from '../dist/ngfactory/src/app/app.server.module.ngfactory'
import * as express from 'express';
import { readFileSync } from 'fs';
import { join } from 'path';
const PORT = 4000;
enableProdMode();
const app = express();
let template = readFileSync(join(__dirname, '..', 'dist', 'index.html')).toString();
app.engine('html', (_, options, callback) => {
const opts = { document: template, url: options.req.url };
renderModuleFactory(AppServerModuleNgFactory, opts)
.then(html => callback(null, html));
});
app.set('view engine', 'html');
app.set('views', 'src')
app.get('*.*', express.static(join(__dirname, '..', 'dist')));
app.get('*', (req, res) => {
res.render('index', { req });
});
app.listen(PORT, () => {
console.log(`listening on http://localhost:${PORT}!`);
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:18
Top Results From Across the Web
Unknown error: SyntaxError: Unexpected token 'export' on ng ...
I've purged node sudo apt-get purge nodejs and reinstalled and removed ng sudo npm remove -g @angular/cli then reinstalled again sudo npm ...
Read more >angular/angular-cli - Gitter
with @webpack, I'm getting typings errors when I ng serve or build.. Is there a missing step in the ... SyntaxError: Unexpected token...
Read more >Unit-Test errors: SyntaxError: Unexpected token export
If I check the mdb.module.ts file inside the ng-mdb-pro folder I can see some reference errors with the MDBBootstrapModulePro exports from the pro...
Read more >nx jest unexpected token 'export' - You.com | The AI Search ...
This means, that a file is not transformed through TypeScript compiler, e.g. because it is a JS file with TS syntax, or it...
Read more >Unexpected token 'export'' mean when running 'npm ... - Quora
It means you're using a version of node that doesn't recognize ES2015 module syntax and, either your code or somewhere in your dependency...
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
i forked the repo few days ago and i made some updates! please try my version and give me your feedback. If that works your machine, i will make a pull request.
So the solution is the following:
npm un --save @ngx-translate/core
npm i --save https://github.com/AnthonyNahas/core.git
Cheers, no more
Unexpected token import error
💃@AnthonyNahas - can you look help us also with localize-router? I think that it’s the same problem. Maybe you can give me a tips how I can manage with this problem?