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.

Unexpected token 'export' for >v3

See original GitHub issue

Hi, I tried to understand for a very long time, but I ran out of ideas. After updating to version 3, tests began to fall with this error, in the place where I call the Api class. The project includes a dependency that was generated using swagger-typescript-api, everything was fine on version 2. Any idea why this is happening? Thanks

Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    /Users/r/project/specifications/lib/index.js:16
    export class HttpClient {
    ^^^^^^

    SyntaxError: Unexpected token 'export'

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
navyfoxcommented, Jan 15, 2021

@js2me Thanks for the help. You pushed me in the right way. jest.config.json

"transform": {
    "^.+\\.svg$": "<rootDir>/test/transform/svg.js",
    "^.+\\.ts$": "babel-jest",
    "\\.js$": "ts-jest",
    ".*\\.(vue)$": "vue-jest"
  },
"transformIgnorePatterns": [
    "node_modules/(?!@myApi)"
  ],

these lines are needed

"\\.js$": "ts-jest",
"transformIgnorePatterns": [
    "node_modules/(?!@myApi)"
  ],
0reactions
navyfoxcommented, Jan 15, 2021

@js2me Yes

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Unexpected Token Export - javascript - Stack Overflow
The problem was that I was changing my code from non-modules to modules and I forgot to delete the imported script file. My...
Read more >
Problem with Nuxt3: Unexpected token 'export' #333 - GitHub
I've found a temporary solution. Rename the plugin to fontawesome.client.js, and remove it from nuxt.config.js (Nuxt3 automatically loads it).
Read more >
How to fix SyntaxError: Unexpected token 'export' in JavaScript?
In this article, we are going to see How to fix SyntaxError: Unexpected token 'export' in JavaScript? and what are Es6 modules.
Read more >
SyntaxError: Unexpected token 'export' - Abhishek Kumar
In case you are getting error like 'Unexpected token export' while starting the server, then export like below in schema.js
Read more >
syntaxerror unexpected token 'export' typescript - You.com
The "Uncaught SyntaxError Unexpected token 'export'" occurs for 2 main reasons: Using the ES6 Module syntax in a Node.js application without type to...
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