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.

Angular 6+: SyntaxError: Unexpected token import

See original GitHub issue

Its not working for me. I am using Angular 6+ but I always get this error:

src\setup-jest.ts:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import 'jest-preset-angular';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)


What can be the issue? How can we resolve it?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

6reactions
ahnpnlcommented, Aug 21, 2018

hi all, please add "module": "commonjs", to your tsconfig.spec.json. It will solve your issue 😃

5reactions
ahnpnlcommented, Aug 21, 2018

@l7960261 you can try to run clear cache of jest, it should solve after modifying tsconfig.spec.json. It worked for me. Here is the repo

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Resolve Typescript Error Unexpected Token Import?
Uncaught SyntaxError: Unexpected token import at src/test.js:1. My tsconfig.json in the \src folder is as follows:
Read more >
missing file lib/angular2-modal/plugins/bootstrap.js
I am working on angular2-modal popup, after compiling when I try to launch the application I am getting this error in browser console,...
Read more >
Unexpected token import; After updating from Angular 2 RC5 ...
Coding example for the question Uncaught SyntaxError: Unexpected token import; After updating from Angular 2 RC5 to Angular 2 Final;-angular.js.
Read more >
SyntaxError: Unexpected token - JavaScript - MDN Web Docs
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided.
Read more >
node unexpected token export - You.com | The AI Search ...
Node.js - SyntaxError: Unexpected token import ... While you are tranpiling your own source files, angular is deployed as ES2015 ... Answered on...
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