前言

使用npm最新版本时,会出现以下的警告信息

1
2
3
4
5
› npm view npm version
(node:6136) ExperimentalWarning: CommonJS module C:\Users\ZSYY\AppData\Roaming\npm\node_modules\npm\node_modules\debug\src\node.js is loading ES Module C:\Users\ZSYY\AppData\Roaming\npm\node_modules\npm\node_modules\supports-color\index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
10.9.2

虽然没有什么影响,但是看着很烦,可以通过下面的方法来屏蔽警告信息。

Windows下设置环境变量

变量名:NODE_OPTIONS
变量值:--disable-warning=ExperimentalWarning

1
NODE_OPTIONS='--disable-warning=ExperimentalWarning'

如下图所示

Linux下设置环境变量

1
export NODE_OPTIONS='--disable-warning=ExperimentalWarning'

参考链接:[BUG] ExperimentalWarning: Support for loading ES Module in require() is an experimental feature and might change at any time