Vite 和 Antd 错误 -> [vite:css] 未启用内联 JavaScript。你的选项里有设置吗?

Nik*_*kos 3 less reactjs create-react-app antd vite

我不知道如何解决从 CRA 迁移到 vite 时出现的错误。

\n
> vite build\n\nvite v2.9.13 building for production...\n\xe2\x9c\x93 3811 modules transformed.\n[vite:css] Inline JavaScript is not enabled. Is it set in your options?\nfile: /Users/nikos/WebstormProjects/web/node_modules/.pnpm/antd@4.21.4_react-dom@17.0.2+react@17.0.2/node_modules/antd/es/date-picker/style/index.less:110:0\nerror during build:\nError: Inline JavaScript is not enabled. Is it set in your options?\n    at less (/Users/nikos/WebstormProjects/web/node_modules/.pnpm/vite@2.9.13_less@4.1.3+sass@1.53.0/node_modules/vite/dist/node/chunks/dep-80fe9c6b.js:38106:33)\n    at async compileCSS (/Users/nikos/WebstormProjects/...\n
Run Code Online (Sandbox Code Playgroud)\n

如果我将其添加到 Vite 配置中

\n
  less: {\n    javascriptEnabled: true,\n  },\n
Run Code Online (Sandbox Code Playgroud)\n

它变为

\n

file: /Users/nikos/WebstormProjects/web/node_modules/.pnpm/antd@4.21.4_react-dom@17.0.2+react@17.0.2/node_modules/antd/es/tag/style/index.less:110:0\n其中包含:

\n

在此输入图像描述

\n

Nik*_*kos 9

将其添加到您的 vite 配置中

  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        additionalData: '@root-entry-name: default;',
      },
    },
  },
Run Code Online (Sandbox Code Playgroud)