less报错,Error evaluating function `unit`: the first argument to unit must be a number.

lbnnbs / 2024-02-09 / 原文

1、less-loader 版本太高了,可以降低版本

2、lessc 的执行参数里面增加一个参数 --math=always

3、可以关闭严格模式

{
    loader: "less-loader",
    options: {
      lessOptions: {
        strictMath: false,
      },
    },
},

 

4、vite配置可以设置 math: "always",

export default defineConfig({
    plugins: [
        uni(),
    ],
    css: {
        preprocessorOptions: {
            less: {
                javascriptEnabled: true,
                math: "always",
            },
        },
    },
})