I'm working on a Nuxt 4 project and sometimes, after I update a file, J got the following error in the browser console:
Uncaught (in promise) SyntaxError: Identifier 'validate' has already been declared (at virtual:nuxt:/home/nicolas/Desktop/projets-web/wimefront/.nuxt/middleware.mjs:2:1)
Inspecting the generated .nuxt/middleware.mjs, I can see this:
import validate from "/_nuxt/@fs/home/nicolas/Desktop/projets-web/wimefront/node_modules/nuxt/dist/pages/runtime/validate.js?v=3712f6c6";
import validate from "/_nuxt/@fs/home/nicolas/Desktop/projets-web/wimefront/node_modules/nuxt/dist/pages/runtime/validate.js?v=3712f6c6"; // duplicated
import manifest_45route_45rule from "/_nuxt/@fs/home/nicolas/Desktop/projets-web/wimefront/node_modules/nuxt/dist/app/middleware/manifest-route-rule.js?v=3712f6c6";
export const globalMiddleware = [
validate,
validate,
manifest_45route_45rule
];
export const namedMiddleware = {
auth: () => import("/_nuxt/middleware/auth.js")
};
I do not have any validate.js or validate.ts in my middleware/ or pages/ folder. I only have one custom middleware file, and it doesn't export or declare anything named validate.
I’ve tried:
rm -rf .nuxt node_modules + fresh npm install
Confirming I have no duplicate files named validate
Still, Nuxt seems to import the same internal validate.js file twice and crashes.
Almost every time I change something in a vue file, I need to do npm dev again (after npm dev I don't have the error)
Any clue?