-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Vitest Browser Mode 2.1.4 regression: ReferenceError: process is not defined
#6872
Comments
|
Hmm, I remember they have many export default defineConfig({
define: {
'process.env': JSON.stringify({})
}
}) This should give mostly same behavior as v2.1.3. |
Yes, I believe the offending line is this one: https://github.com/vercel/next.js/blob/d8c1875800903542bd4e89116f4c8aa32cc853bf/packages/next/src/client/has-base-path.ts#L3 |
So I guess this is because of #6718 which landed in 2.1.4? |
Yes, that PR. there shouldn't be |
No worries, it seems like explicitly defining |
Sorry, I spoke too soon. That fix only works if you're not using Vitest workspaces. When I went to apply it to my actual project, the I've updated the reproduction to show this: https://github.com/ezzatron/vitest-browser-process-not-defined-repro/actions/runs/11714232660 |
Okay, that could be a different workspace issue. You need to use either // vitest.config.ts
import react from "@vitejs/plugin-react";
import { defineConfig } from "vitest/config";
export default defineConfig({
plugins: [react()],
define: {
"process.env": JSON.stringify({}),
},
test: {
watch: false,
},
});
// vitest.workspace.ts
import react from "@vitejs/plugin-react";
import { defineProject, defineWorkspace } from "vitest/config";
export default defineWorkspace([
{
extends: './vitest.config.ts',
test: {
name: "project",
browser: {
enabled: true,
headless: true,
provider: "playwright",
name: "chromium",
},
},
},
]); or point to a dedicated config file from workspace // vitest.config.browser.ts
import react from "@vitejs/plugin-react";
import { defineConfig } from "vitest/config";
export default defineConfig({
plugins: [react()],
define: {
"process.env": JSON.stringify({}),
},
test: {
name: "project",
browser: {
enabled: true,
headless: true,
provider: "playwright",
name: "chromium",
},
},
});
// vitest.workspace.ts
export default defineWorkspace([
'./vitest.config.browser.ts'
]); I'm not exactly sure if this is a bug or not. We know there is some limitations regarding how we can pass config object to browser mode and things work better if there is a dedicated config file for browser mode vite server to consume. Probably similar to #5015 |
Thank you! Can confirm that using |
I'm investigating further and I'm not sure what I said in #6872 (comment) is correct. It looks like there's something odd going on specifically to (But again, having a dedicated config file for browser mode should work more consistent with normal Vite dev usage.) |
Sounds good, will keep an eye out for it. Appreciate the help 🙏 |
Describe the bug
When using Vitest Browser Mode with Next.js + the
next/link
component, there's a regression in Vitest2.1.4
that produces the following error:Possibly related to #6842.
Reproduction
See https://github.com/ezzatron/vitest-browser-process-not-defined-repro
You can see the repo working under Vitest
2.1.3
and not working under2.1.4
here: https://github.com/ezzatron/vitest-browser-process-not-defined-repro/actions/runs/11713569546:System Info
Not relevant, happens under GHA and locally on my machine, but anyway:
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: