-
Notifications
You must be signed in to change notification settings - Fork 0
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
Jest tests SyntaxError: Cannot use import statement outside a module
#8
Comments
I found a post suggesting to use "jest": {
"transformIgnorePatterns: "node_modules/(?!@some-package)"
} However, putting it in the arguments to the |
I found another post suggesting that create-react-app does some overwriting of the Jest configuration. Looking through it's clear that it does in fact replace the default values of More investigation uncovered that I have found an issue on GitHub corroborating this issue, where the solution was to add a line to the documentation pointing out this issue.
The actual solution is to either use the scripts method in the "scripts": {
"test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!your-module-name)/\"",
} Or, alternatively, to keep the scripts clean, you can add the ignore pattern to the const jestConfig = (c) => ({
...c,
transformIgnorePatterns: [
...c.transformIgnorePatterns.reduce(
(prev, current) =>
current.includes("node_modules") ? prev : [...prev, current],
[]
),
"[/\\\\]node_modules[/\\\\](?!@some-package).+\\.(js|jsx|mjs|cjs|ts|tsx)$",
],
}); The latter code snippet allows for the addition of a new pattern while still maintaining the original patterns. |
One more discovery, in order to properly attach the const options = override(); // some combination of plugins
const jestConfig = (c) => c; // some function like the one above that updates the config
options.jest = jestConfig;
module.export = option; And it is important to note that the |
Encountered this issue later down the road in a different project, and found there's a new potential thread. When using Babel to compile the tests, you cannot utilize a See this line from the Babel documentation:
|
When executing Jest tests with a particular proprietary library, I was receiving the following exception(s). For security purposes, I have obfuscated the official package names and paths.
Or, a similar exception
The text was updated successfully, but these errors were encountered: