You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
edit: Not sure this is a problem with ts-jest. I get the same issue from react-markdown when I import it in a project that doesn't have ts-jest installed.
Here's the error I get from Jest when trying to run tests for components that import a module from node_modules/ that is only available as ESModules...
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/[...]/node_modules/react-markdown/index.js:5
import { ReactMarkdown } from './lib/react-markdown.js';
^^^^^^
SyntaxError: Cannot use import statement outside a module
> 1 | import ReactMarkdown from 'react-markdown'
I'm essentially having the same problem as #2579, but the workaround posted in that issue did not work for me. This isn't really an "issue" with ts-jest so I opted for this discussion, but I'm not entirely sure if this is even the right place for it. So feel free to close if y'all feel I should be posting this in a more general forum for Jest users.
This works totally fine in my application, I can see rendered Markdown and nothing blows up...Jest is the only tool that seems to have a problem with what I'm doing.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
edit: Not sure this is a problem with
ts-jest
. I get the same issue fromreact-markdown
when I import it in a project that doesn't have ts-jest installed.Here's the error I get from Jest when trying to run tests for components that import a module from
node_modules/
that is only available as ESModules...My Jest config looks like this:
I'm essentially having the same problem as #2579, but the workaround posted in that issue did not work for me. This isn't really an "issue" with ts-jest so I opted for this discussion, but I'm not entirely sure if this is even the right place for it. So feel free to close if y'all feel I should be posting this in a more general forum for Jest users.
This works totally fine in my application, I can see rendered Markdown and nothing blows up...Jest is the only tool that seems to have a problem with what I'm doing.
Beta Was this translation helpful? Give feedback.
All reactions