升级node@22后运行npm install报错 distutils not found
从node@20升级到node22后,在运行 npm install
的时候报了很多 gyp 错误,其中包括 npm error npm error ModuleNotFoundError: No module named 'distutils'
。
问题原因是我在使用 brew install node@22
的过程中自动把 python 升级到了 3.13。而 distutils module 在 python 3.12 中被移除了,此时就需要我们手动安装 setuptools
来解决,比如:
python3 -m pip install setuptools或者如果是使用homebrew安装的话,使用下面命令安装brew install python-setuptools
然后重新运行 npm install
,问题解决。