vitest-react-native
vitest-react-native copied to clipboard
Compatibility with @testing-library/react-native
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.