agentcooper / react-pdf-highlighter

Set of React components for PDF annotation

Home Page:https://agentcooper.github.io/react-pdf-highlighter/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

JonBergman opened this issue · comments

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

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.

Might be fixed by 5.1.0.