在使用commander和shelljs开发终端命令行的过程中,发现只要一运行所开发的命令,就会出现大段警告,类似这样:
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11591) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency
(node:11591) Warning: Accessing non-existent property 'chmod' of module exports inside circular dependency
(node:11591) Warning: Accessing non-existent property 'cp' of module exports inside circular dependency
(node:11591) Warning: Accessing non-existent property 'dirs' of module exports inside circular dependency
(node:11591) Warning: Accessing non-existent property 'pushd' of module exports inside circular dependency
(node:11591) Warning: Accessing non-existent property 'popd' of module exports inside circular dependency
(node:11591) Warning: Accessing non-existent property 'echo' of module exports inside circular dependency
(node:11591) Warning: Accessing non-existent property 'tempdir' of module exports inside circular dependency
(node:11591) Warning: Accessing non-existent property 'pwd' of module exports inside circular dependency
(node:11591) Warning: Accessing non-existent property 'exec' of module exports inside circular dependency
(node:11591) Warning: Accessing non-existent property 'ls' of module exports inside circular dependency
在百度上搜了下,说是node版本14导致的问题,要将node降版本到12,可是公司前端统一都用14,降版本肯定是不行的。。。。
所以我又去github上看了一圈,发现也有人遇到这种情况。https://github.com/nodejs/node/issues/32987
这个人说他将shelljs升级到0.8.4就不会出现警告了,我试了下,将0.8.2升级到0.8.4,有一个命令的确不会产生警告了!但是另一个命令依然会产生警告。
去看了同事开发的命令行,发现他的commander的版本是9.0.0,而我的版本只有2.16.0,尝试升级到9.0.0之后就解决了问题,终端控制台上不会输出警告了。