sheremet-va / vitest-react-native

54 stars 4 forks source link

Compatibility with @testing-library/react-native #15

Open wojtekmaj opened 4 months ago

wojtekmaj commented 4 months ago

As soon as I setup app using @testing-library/react-native, I get:

SyntaxError: Cannot use import statement outside a module
 ❯ Object.<anonymous> node_modules/@testing-library/react-native/src/helpers/format-default.ts:1:1

Module /node_modules/react-native/index.js:14 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "react-native" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.

As a temporary workaround you can try to inline the package by updating your config:

// vitest.config.js
export default {
  test: {
    server: {
      deps: {
        inline: [
          "react-native"
        ]
      }
    }
  }
}

I previously raised #5 and closed it, but it seems the same issue is now "passed over" to @testing-library/react-native.

wojtekmaj commented 4 months ago

It seems the issue might be:

var _reactNative = require("react-native");
berdyshev commented 3 months ago

is there any updates on that issue?

camilossantos2809 commented 2 months ago

I'm having a similar problem, but with other dependency:

SyntaxError: Cannot use import statement outside a module
 ❯ Object.newLoader [as .js] node_modules/pirates/lib/index.js:121:7
Lili0114 commented 2 months ago

I have the same error message except it appears for a firebase import, I tried a lot of things, but nothing seems to work.

YuriiLutsykSPRO commented 1 month ago

The same issue, we can't add any related configs to react native library (as @testing-library/react-native or react-native-unistyles) to the setup file in vitest.config. It's really a big blocker