npm i and npm update breaking gulp, browserify builds

自闭症网瘾萝莉.ら 提交于 2019-12-06 13:28:59

The process of fixing this went as follows:

  1. Uninstall node and npm

    • If using Homebrew, simply do brew uninstall node
  2. Delete /usr/local/lib/node_modules (make a list of what's in there for future reference)

  3. Reinstall node with brew install node --without-npm. This part is important, as node natively pulls in npm. npm doesn't appreciate Homebrew's all-controlling demeanor, though and I think this, at least partially, contributed to my issues.

  4. The current curl install process being passed around does NOT work on the latest OSX. You'll receive an error, but the installation will still look successful -- at least until you run npm -v and receive npm: Command not found. You need to do this process (thanks to zmilonas @ https://gist.github.com/DanHerbert/9520689):

export NPM_VERSION=6.1.0

export NPM_PREFIX_FROM_RC=$(test -f ~/.npmrc && cat ~/.npmrc | awk -F'=' '{print $NF}')

export NPM_PREFIX=${NPM_PREFIX_FROM_RC:=~/.npm-packages}

curl -O https://registry.npmjs.org/npm/-/npm-${NPM_VERSION}.tgz && \

tar xzf npm-${NPM_VERSION}.tgz && \

cd package && \

node bin/npm-cli.js install -gf --prefix=${NPM_PREFIX} ../npm-${NPM_VERSION}.tgz && \

cd .. && \

rm -rf package npm-${NPM_VERSION}.tgz

  1. Set NODE_PATH to: export $NODE_PATH="/Users/<your-username>/.npm-packages/lib/node_modules"

  2. You can also add the command in step 5 to ~/.bash_profile` as to retain this environment variable upon restart.

  3. Run npm install -g <package> for each package that was previously in /usr/local/lib/node_modules

  4. Remove your old node_modules from your project directory and run npm install. This should take care of any breakages that occurred due to the update.

  5. Run a test build. This should resolve any of the issues you were having, much like they resolved mine. While this hasn't fixed everything, this process is what it took to repair my broken npm/node install and narrow down what and where the actual issue is in my project.

Keep in mind the above is for the latest MacOS, and may not be necessary for Linux or Windows.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!