nuxt / nuxt

The Intuitive Vue Framework.
https://nuxt.com
MIT License
52.3k stars 4.78k forks source link

The CJS build of Vite's Node API is deprecated. #27110

Closed 332lfgb6 closed 1 week ago

332lfgb6 commented 1 week ago

Environment

Reproduction

No repo needed

Describe the bug

When I use the official legacy plugin, I get this warning image

import legacy from "@vitejs/plugin-legacy";

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },
  vite: {
    plugins: [
      legacy({
         targets: ["Chrome 63", "ios 9"],
         modernPolyfills: true,
      }),
    ],
  },
});
{
"dependencies": {
    "nuxt": "^3.11.2",
  },
  "devDependencies": {
    "@vitejs/plugin-legacy": "^5.4.0",
  }
}

Additional context

No response

Logs

No response

danielroe commented 1 week ago

This is because jiti (which we use to transpile the nuxt.config in c12 is loading the file in a CJS context.

@pi0 might have an idea about how to force ESM resolution of Vite, or a workaround here.

pi0 commented 1 week ago

You can use VITE_CJS_IGNORE_WARNING=1 environment variable to hide this warning. Once vite completely drops CJS entrypoint OR when jiti v2 is landed and c12 (and nuxt) adopts it, it will be resolved.