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

Create React App Jest: SyntaxError: Cannot use import statement outside a module #122

Closed
JonBergman opened this issue Mar 23, 2021 · 2 comments

Comments

@JonBergman
Copy link

When running tests on a create-react-app build jest is unable to import react-pdf-highlighter components.

Details:

    /mypath/node_modules/react-pdf-highlighter/build/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import PdfHighlighter from "./components/PdfHighlighter";
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module
@johnn134
Copy link

I've been tackling these problems trying to get react-pdf-highlighter working on a recent project. If you take a look at this comment on this thread you should see a basic fix for your problem:
facebook/create-react-app#9938 (comment)

Essentially, CRA has problems with reading the "jest" property in package.json. Therefore, you need to edit the test script to include this at the end:
react-scripts test --transformIgnorePatterns \"<rootDir>/node_modules/(?!react-pdf-highlighter)/\"

This will babel transpile the module during jest tests.

@agentcooper
Copy link
Owner

Might be fixed by 5.1.0.

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