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.

ng build - Unexpected token import error.

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:18

github_iconTop GitHub Comments

4reactions
AnthonyNahascommented, Sep 12, 2017

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:

  1. remove the npm module via npm un --save @ngx-translate/core
  2. install my forked module via npm i --save git+ssh://git@github.com:AnthonyNahas/core.git or npm i --save https://github.com/AnthonyNahas/core.git

Cheers, no more Unexpected token import error 💃

1reaction
qubiackcommented, Oct 22, 2017

@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?

/home/xxx/Projects/private/angular4-cli-seed/node_modules/localize-router/src/localize-router.config.js:1
(function (exports, require, module, __filename, __dirname) { import { Inject, OpaqueToken } from '@angular/core';
Read more comments on GitHub >

github_iconTop 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 >

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