Jest Fails to Parse TypeScript Files with ES Module Syntax #4657
bcostaaa01
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
Hey all. I'm encountering an issue where Jest fails to parse TypeScript files that use ES module syntax. I am using shadcn in a Webpack-scaffolded React project. The error message indicates that Jest encountered an unexpected token when trying to parse an [import] statement in a TypeScript file, however I can't seem to find why it is triggering that issue. I tried different approaches, modifying the babel, jest, and even the TypeScript config, but no success :(
Error Message:
Steps to Reproduce the Error:
Create a TypeScript file with ES module syntax, e.g., [
skeleton.tsx
]:Import and use this component in another file, e.g., [
ComponentThatUsesSkeleton.jsx
]:Run Jest tests.
Configuration Files:
[
tsconfig.json
][
jest.config.js
]:[
.babelrc
]:[
babel.config.js
]:Expected Behavior:
I guess that Jest should correctly parse and run tests on TypeScript files that use ES module syntax.
Actual Behavior:
Jest fails to parse TypeScript files with ES module syntax, resulting in a
SyntaxError: Cannot use import statement outside a module
.Thank you in advance! :)
Beta Was this translation helpful? Give feedback.
All reactions