Skip to content
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

react ts app yarn test:unit fails with SyntaxError: Cannot use import statement outside a module #17

Open
pnwcoder2020 opened this issue Jul 31, 2021 · 3 comments

Comments

@pnwcoder2020
Copy link

Thank you for your work on this package and apologies in advance if this issue is the result of user error.

I see the following error in the example react-app-ts and also when incorporating vite-jest into my own react app.

/code/vite-jest/examples/react-app-ts/node_modules/vite-jest/bin/vite-jest.js:3
import fs from 'fs'
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Module._compile (internal/modules/cjs/loader.js:895:18)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
@mason-smith
Copy link

mason-smith commented Aug 27, 2021

I am getting a very similar issue specifically when testing React components following the same example. In this case, react-hook-form seems to be the offender.

Screen Shot 2021-08-27 at 10 11 29 AM

I can post more details if that is helpful

Maybe more related to #11 though now that I read through it

Edit: for clarification this is using npm v7.19.0

@mijamo
Copy link

mijamo commented Sep 10, 2021

I think this is a Yarn 2 specific problem, and to be more specific this is because Yarn 2 cannot currently run ES Modules.

See yarnpkg/berry#638

When I try to run the example with pnpm it works, but not using yarn

@mason-smith
Copy link

@mijamo The error in my screenshot was with npm v7.19.0. I have not tried pnpm, although I did observe the same issue with Yarn 2 as you indicated as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants