作为前端在开发过程中的小tip

347 阅读2分钟

1、用包管理工具n安装node报错:

Failed to connect to github.com port 443: Timed out

解决方案:

git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy

2、sourcetree 密码过期:

git config --global credential.helper osxkeychain

后git push代码 重新输入密码即可

3、调试本地npm包:

场景:项目A项使用项目B本地包调试:

  1. 在项目B执行:
npm link
  1. 在项目A执行
npm link xxxx  // A的packjson中名字

这样B改动编译后,A那里就可以看到变动了

4. umi安装react-virtuoso报错,??编译失败

需要在配置config那里添加额外要编译的包

export default defineConfig({
  //配置添加额外需要编译的
  nodeModulesTransform: {
    type: 'none',
  },
  routes: routes,
  //快速刷新,开发时可以保持组件状态
  fastRefresh: {},
  //防止缓存
  hash: true,
  //本地开发,接口转发
  proxy: {},
  //静态资源地址
  publicPath: getPublicPath(),
  extraBabelIncludes: ['react-virtuoso'],
});

4. npm i 的过程中,报# cancel after 1 retries!

在安装老项目的时候报的错,使用n切换到老的node:v12.16.2,但是npm还是高版本的,

npm install --global npm@5.6.0 
//或者mac环境下:
sudo npm install --global npm@5.6.0 --unsafe-perm=true --allow-root

降低npm的版本就可以了,如果不行,可以试着

  • npm cache -f clean
  • rm -rf node_modules/
  • ...

然后再npm i

5、 autojump,使用j + 文件目录,无法跳转且报错:

j xxx
env: python: No such file or directory
autojump: directory 'demo' not found

Try `autojump --help` for more information.

解决方法: 因为 MacOS Monterey 12.3 系统更新了自带的python问题

ln -s /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/bin/python3 /usr/local/bin/python3

ln -s -f /usr/local/bin/python3 /usr/local/bin/python

执行这两句后就OK了: image.png

如果还不ok:尝试下面办法:

where autojump
image.png

给/Users/xiaoshanyu/.autojump/bin/autojump文件的第一行,改为python3就可以了,双击执行

image.png

6、mac 每次系统升级都会报错

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools),
missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

目前没有别的办法:

$ xcode-select --install

等他安装完就OK了

7、github提交的的时候,kex_exchange_identification: Connection closed by remote host解决方法

kex_exchange_identification: Connection closed by remote host
vim ~/.ssh/config 
// 修改.ssh/config 为并保存退出:
Host github.com
  HostName ssh.github.com
  User git
  Port 443
 
// 然后终端执行  
ssh -T git@github.com 
回复yes,点击回车

8、控制台报错,但是接口有返回值

Unhandled Rejection (TypeError): Failed to fetch 

原因:检查响应头中的Access-Control-Allow-Origin的值。通常情况下,当响应头的Access-Control-Allow-Origin和请求的来源不匹配时,即使收到响应,fetch API也会抛出获取失败。

9、报错ReferenceError: __webpack_base_uri__ is not defined, 需要重装webpack

npm uninstall webpack -D
npm i webpack -D

9、# Unable to load ‘@webpack-cli/serve command问题解决

解决办法: 删除node_modules 和lock文件, 更改webpack-cli版本成4.9.0,然后重新运行npm run dev

10、git 回滚到某个版本 并且强制推送到远程 image.png 未完待续