Vitest fails to run if next.config.js imports next-intl/plugin #1943
Closed
cupofjoakim
started this conversation in
General
Replies: 1 comment 1 reply
-
As soon as I posted I found the cause. The real issue seems to be that we import the next config into our test setup, which then would require the plugin and fail. That being said, we still need that config for unrelated reasons, so our current workaround is this:
I'm sure this also has drawbacks, but it's clear to me that this is a code organisation issue on our end and not something to be discussed here. I would love a better error message though, I lost quite a lot of time here. |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
Preface: I might be doing something wrong but I'm not seeing it.
I'm currently in the midst of implementing next-intl routing for a pretty large nextjs app with pages router.
Vitest is unable to run any of my 129 test suites if I import next-intl/plugin in next.config.js. It fails with this error:
This happens regardless if I call the
createNextIntlPlugin()
function or not.I've followed the testing docs and added the next-intl exclusion in vitest.config.ts
I'm unsure if I'm missing something, but the main issue seems to be that the plugin import happening with
createRequire
here: https://github.com/amannn/next-intl/blob/main/packages/next-intl/src/plugin/hasStableTurboConfig.tsx#L4.Looking at the source code, createRequire checks if
document
is present, and if it is, it usesdocument.baseUri
and tries fetching plugin.cjs, which then fails. I'm confused as to wheredocument
gets defined here, considering that your examples seem to work fine and you do use jsdom in one of them.I'm currently on the latest lts version, node 22.17.0.
Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions