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

SyntaxError: Cannot use import statement outside a module when running tests. #12

Closed
drzamich opened this issue Jul 9, 2020 · 3 comments

Comments

@drzamich
Copy link

drzamich commented Jul 9, 2020

Hi. I imported react-frappe-charts in my app created with Create React App. It works fine but when I try to run any unit tests I get an error

  ● Test suite failed to run

    /node_modules/react-frappe-charts/build/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React from "react";
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

I believe this is because the library is using ES6 modules in production. Would you consider transpiling the code before publishing to npm?

Meanwhile, Can anyone think of a workaround so that I can run my tests?

@sheshbabu
Copy link
Owner

Hi @drzamich, you can try transpiling this module when running test. Can you try this suggestion - jestjs/jest#6229 (comment)

@sheshbabu
Copy link
Owner

Closed due to inactivity. @drzamich Please feel free to reopen if you're still facing this issue 🙂

@aquiab
Copy link

aquiab commented Sep 21, 2022

got around it by setting my jest config with
"transformIgnorePatterns": ["/node_modules/(?!(react-frappe-charts|frappe-charts)/)"]
and changing .babelrc to babel.config.js and module exporting it

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

3 participants