Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular 6+: SyntaxError: Unexpected token import #185

Closed
ayyazzafar opened this issue Aug 16, 2018 · 8 comments
Closed

Angular 6+: SyntaxError: Unexpected token import #185

ayyazzafar opened this issue Aug 16, 2018 · 8 comments

Comments

@ayyazzafar
Copy link

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?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Aug 16, 2018

hi, can you please follow the example app in this repository and see if it can help ?

@l7960261
Copy link

same issue as @ayyazzafar

@joelmuskwe
Copy link

same issue too

@ahnpnl
Copy link
Collaborator

ahnpnl commented Aug 21, 2018

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

@l7960261
Copy link

Hello ,
I use ng new jest-into-angular project (repo)

with steps but same issue

@ahnpnl
Copy link
Collaborator

ahnpnl commented 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

@l7960261
Copy link

@ahnpnl Cool. It's work fine.

@boazrymland
Copy link

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

This should be added to the compilerOptions section of the mentioned file, not in its root.
Only after I moved this to the correct location it worked out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants