-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
[CRA v5] Jest + React-markdown = Must use import to load ES Module #11946
Comments
Not sure if this helps but I managed to get my react-markdown tests to run with CRA by modifying the test command
|
@KieranDotCo Thanks for the hand. Unfortunately, this doesn't seem to do the trick with CRA v5. The same error occurs. |
Try the solution suggested here: remarkjs/react-markdown#635 (comment) |
@yuchen-w Thanks but it looks like those solutions target CRA 4.x (and I'd really like to avoid the mocking approach) |
@nulltoken I am using this solution on CRA v5. // package.json "jest": {
"transformIgnorePatterns": [
"(?!(/node_modules/(react-markdown|vfile|vfile-message|unist-.*|unified|bail|is-plain-obj|trough|remark-.*|mdast-util-.*|micromark.*|decode-named-character-reference|character-entities|property-information|hast-util-whitespace|space-separated-tokens|comma-separated-tokens|pretty-bytes)/))(/node_modules/.+.(js|jsx|mjs|cjs|ts|tsx)$)",
"^.+.module.(css|sass|scss)$"
]
} |
@esetnik had to slightly modify the pattern for me. This worked for me on a MacBook: "jest": {
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\](?!(react-markdown|vfile|vfile-message|markdown-table|unist-.*|unified|bail|is-plain-obj|trough|remark-.*|mdast-util-.*|escape-string-regexp|micromark.*|decode-named-character-reference|character-entities|property-information|hast-util-whitespace|space-separated-tokens|comma-separated-tokens|pretty-bytes|ccount)).+\\.(js|jsx|mjs|cjs|ts|tsx)$"
]
}, |
@jcgentr and @esetnik answers didn't work for me. However, they pointed me in the correct direction. Especially because those solutions work for projects created with
Basically, I just added these patterns:
If running the tests still fails for you because |
@martenmatrix This worked for me, thank you so much! |
* feat: ✨ display source code directly without maintaining extra .md files * fix: 🔧 fix broken test caused by react-markdown references: 1.facebook/create-react-app#11946 2.https://stackoverflow.com/questions/49263429/jest-gives-an-error-syntaxerror-unexpected-token-export * fix: update title tag to PPM * chore: clean up code; update homepage route * feat: stack and display source code
I used Option 1 in Recommended solution by react-markdown |
Guys, you can see a lot of likes under the previous entries, and in you, as well as me, the tests still don't work.
This solved my problem. |
@Slisarenko Great you figured it out. Do you mind sharing the relevant parts of your |
@fbruckhoff No problem, here:
babel.config.js:
|
Describe the bug
Running a CRA test rendering
react-markdown
leads to an error message "Must use import to load ES Module:"A (somewhat) related issue in remarkjs/react-markdown#635 seems to redirect to https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c, which in turn states "Create React App doesn't yet fully support ESM. I would recommend opening an issue on their repo with the problem you have encountered. One known issue is #10933."
/cc @ChristianMurphy
Did you try recovering your dependencies?
Yes
Which terms did you search for in User Guide?
esm
Environment
Windows
Steps to reproduce
Full repro case is available at
yarn test
Output of
yarn test
can be reviewed at https://github.com/nulltoken/repro-react-markdown-cra-esm/runs/4841320780?check_suite_focus=trueExpected behavior
I'd very much like the test not to fail because of an import issue :-/
Actual behavior
Reproducible demo
(Paste the link to an example project and exact instructions to reproduce the issue.)
The text was updated successfully, but these errors were encountered: