最近,当我编译我的scss文件时,我得到一个错误。错误信息如下:

Browserslist: canius -lite已经过时。请运行下一个命令npm update canius -lite browserslist

首先,正如消息所说,我运行npm update canius -lite browserslist,但它没有解决这个问题。 我删除了整个node_modules目录并重新安装,我也通过npm update更新了整个文件夹,但没有一个解决了这个问题。 我还重新安装了autoprefixer和browserslist,但没有一个解决问题。

如果我移除

"options": {
      "autoPrefix": "> 1%"
    }

从我的编译配置。Json,一切都很好,这意味着它可能与autoprefixer有关。另外,我手动将包版本更改为包上的最新版本。Json和重新安装,但没有运气。


当前回答

如果你使用纱线:

yarn upgrade

帮帮我吧

其他回答

听起来好像你在使用Visual Studio的Web Compiler扩展。这里有一个开放的问题:https://github.com/madskristensen/WebCompiler/issues/413

在那个问题上有一个解决方案:

关闭Visual Studio 转到C:\Users\USERNAME\AppData\Local\Temp\WebCompilerX.X。X (X是WebCompiler的版本) 在“node_modules”文件夹中删除以下文件夹:caniuse-lite和browserslist 打开CMD(在C:\Users\USERNAME\AppData\Local\Temp\WebCompilerX.X.X内部),运行:npm i caniuse-lite browserslist

正如Scott Kuhl的回答中提到的,这个问题在 https://github.com/madskristensen/WebCompiler/issues/413

对我来说,运行命令npm i canius -lite- browserslist只工作了大约1/2天,就再次出现问题。

下面的解决方案,在帖子中提到,工作得更好。这将更新node.js文件,使其使用console.log而不是console。返回这些错误时发出警告。

您可以手动更新位于 C:\Users\【用户名】当地\ AppData \ \ Temp \ WebCompiler VersionNumber \ node_modules \ browserslist

或者,为了自动完成,将以下内容添加到.csproj文件中:

右键单击项目文件,选择“卸载项目” 编辑.csproj文件 将以下内容粘贴到项目文件中。我将它粘贴到文件的末尾,在</Project>结束标记之前,在导入构建web编译器包之前。

    <ItemGroup>
        <PackageReference Include="MSBuildTasks" Version="1.5.0.235">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
        </PackageReference>
    </ItemGroup>
    <PropertyGroup>
        <TempFolder>$([System.IO.Path]::GetTempPath())</TempFolder>
    </PropertyGroup>
    <ItemGroup>
        <BrowsersListNodeJsFiles Include="$(TempFolder)\WebCompiler*\node_modules\browserslist\node.js" />
    </ItemGroup>
    <Target Name="BrowsersListWarningsAsInfo" BeforeTargets="WebCompile">
        <FileUpdate Files="@(BrowsersListNodeJsFiles)"
                    Regex="console.warn"
                    ReplacementText="console.log" />
    </Target>

重新加载项目到解决方案中。

有一个环境变量>= 4.5.4,BROWSERSLIST_IGNORE_OLD_DATA,您可以将其设置为true来抑制警告(BROWSERSLIST_IGNORE_OLD_DATA=true)。添加BROWSERSLIST_IGNORE_OLD_DATA环境变量。

下面是来自该提交的相关代码片段,显示了检查该环境变量时的早期救助:

module.exports = {
  // ...
  oldDataWarning: function oldDataWarning (agentsObj) {
    if (dataTimeChecked) return
    dataTimeChecked = true
    if (process.env.BROWSERSLIST_IGNORE_OLD_DATA) return

    // ...
    console.warn(
      'Browserslist: caniuse-lite is outdated. ' +
      'Please run next command `' + command + '`'
    )
    // ...
  }
  // ...
}

我不太确定我的问题在哪里,但我相信这是因为我使用了npm和Yarn中相同的全局包。

我卸载了所有的npm全局包,当再次使用yarn命令时,问题就消失了。

要查看已安装的全局包…

npm:

npm ls -g --depth=0

纱:

yarn global list

然后我卸载了我在npm列表中看到的每个包,使用:

npm uninstall -g <package-name>

尝试这解决了我的问题npx browserslist@latest——update-db