npm镜像源管理工具
Volta一个Node版本管理工具
yalc:可能是最好的前端link调试方案
.npmrc
# https://npm.taobao.org/mirrors
# https://docs.npmjs.com/files/npmrc
# npm config ls -l
# It helps to use the same node.js version always
lts/fermium
# https://registry.npmmirror.com/
# registry = https://registry.npmjs.org
registry = https://registry.npmmirror.com/
sentrycli_cdnurl=https://npm.taobao.org/mirrors/sentry-cli/
engine-strict=true
# tag-version-prefix=""
# message="chore(release): %s :tada:"
# npm config ls -l
# npx unimported
# npx depcheck
auto-install-peers=true
strict-peer-dependencies=false
npm报错合集
- npm代理错误(参考https://blog.csdn.net/Linzsong/article/details/100579883) 解决方法 可尝试依次执行
npm config get proxy
npm config get https-proxy
两者均返回null,否则,执行set null的命令,再安装淘宝镜像
之后可以执行npm install
- 错误代码128(参考https://blog.csdn.net/Linzsong/article/details/100579883) 解决方法: 方法一:
git config --global http.sslverify "false"
方法二:
git config --global url."https://".insteadOf git://
- Hostname/IP does not match certificate’s altnames: Host: registry.cnpmjs.org. is not in the cert’s altnames: DNS: r.cnpmjs.org(参考https://www.cnblogs.com/xscn1230/p/nuonuo1230.html) 原因:未知 解决方法
npm set strict-ssl false
npm config set registry http://registry.npmjs.org/
若yarn安装失败,试试npm i
- CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory( 参考https://www.cnblogs.com/jianxuanbing/p/9331042.html) 原因:内存溢出 解决方法 安装
npm install -g increase-memory-limit
运行
increase-memory-limit
package.json中:
{
"scripts": {
"fix-memory-limit": "cross-env LIMIT=2048 increase-memory-limit"
},
"devDependencies": {
"increase-memory-limit": "^1.0.3",
"cross-env": "^5.0.5"
}
}
执行
npm run fix-memory-limit
pnpm管理node,管理依赖
https://blog.csdn.net/qq_36254947/article/details/131026843 nvm安装了多个node版本npm在其中一个中, 用它官方自带的路径不对是删除不掉的, 因为查询路径给你的也是指向nvm某个node版本的路径, 最后解决办法是用nvm切换你常用的node版本然后一个个用pnpm的删除指令去试
.yarnrc.yml
nodeLinker: node-modules
npmRegistryServer: "http://xxx.com/artifactory/api/npm/npm-down/"
unsafeHttpWhitelist:
- "xxx.com"
- "localhost"
npmScopes:
# 对于 '@storybook' 开头的包,使用特定的registry
storybook:
npmRegistryServer: "http://xxx.com/artifactory/npm-proxy-cache/"
.yarnrc
registry:http://xxx.com/artifactory/api/npm/npm-down/
@storybook/client-logger:registry=http://xxx.com/artifactory/npm-proxy-cache/@storybook/client-logger/-/client-logger-7.6.17.tgz
network-timeout=600000
electron_mirror=http://xxx.com/artifactory/npm-generic-proxy/electron/
ELECTRON_MIRROR=http://xxx.com/artifactory/npm-dist-proxy/electron/
.npmrc
@storybook/client-logger:registry=http://xxx.com:/artifactory/npm-proxy-cache/@storybook/client-logger/-/client-logger-7.6.17.tgz
配置国内镜像源
npm和yarn默认是从国外源站拉取依赖包的,为提高下载速度和稳定性,建议配置为国内镜像源。
yarn registry国内镜像:
yarn config set registry https://registry.npmmirror.com
npm registry国内镜像:
npm config set registry https://registry.npmmirror.com
yarn node-sass国内镜像:
yarn config set SASS_BINARY_SITE https://npmmirror.com/mirrors/node-sass/
npm node-sass国内镜像(仅限于npm < v9的版本):
npm config set SASS_BINARY_SITE https://npmmirror.com/mirrors/node-sass/
※注: 从npm v9 版本开始,npm 命令限制了npm config set 只能设置npm官方规定的config (https://docs.npmjs.com/cli/v9/using-npm/config) 因此无法像旧版本一样设置镜像站了,不过依旧可以通过编辑 ~/.npmrc 文件的方式实现旧版本npm config set的效果。
淘宝官方声明,原先的 http://npm.taobao.org 和 http://registry.npm.taobao.org 域名于2022年5月31日零时起停止服务。新域名如下: 【Web 站点】npmmirror 中国镜像站 【Registry Endpoint】https://registry.npmmirror.com 官方公告原文:(天猪:【望周知】淘宝 NPM 镜像站喊你切换新域名啦)
如果不清楚本地当前yarn或者npm的配置,可以执行以下命令查看:
yarn查看方法:
yarn config list
npm查看方法:
npm config list
npm init --scope=@longmo --yes
会生成
{
"name": "@longmo/electron_builder_auto_move",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
yarn安装时 node版本不匹配
yarn config set ignore-engines true
# 或者 .yarnc中
ignore-engines=true
## 或者
yarn install --ignore-engines
https://classic.yarnpkg.com/en/docs/cli/install#toc-yarn-install-ignore-engines