1. 程式人生 > 其它 >終端警告Warning: Accessing non-existent property '...' of module exports inside circular dependency

終端警告Warning: Accessing non-existent property '...' of module exports inside circular dependency

在使用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之後就解決了問題,終端控制檯上不會輸出警告了。