Skip to content

疑难杂症

锁文件不同步

在初次创建项目的时候未配置npmrc文件,生成的yarn lock 文件中的注册包地址为yarnpkg 官方地址,而后续添加后来的包地址为淘宝镜像地址,在Jenkins打包的时候网络波动导致无法拉取包,导致打包失败。

如何解决

  1. 删除yarn.lock文件 重新安装,注意一些包小版本不兼容会导致失败
  2. 使用pnpm 安装,lock文件不会保存包地址

umi request 拿到response

tsx
const res = await performancestatExportCollegeCoreScoreByGet({
  params: {
    year: query.year ! ,
  },
},
{
  responseType: 'blob',
  getResponse: true,
},
);

文件名未转义导致的问题

上传文件时,文件名未进行转义,导致文件名中包含特殊字符时,无法直接使用 浏览器访问,直接下载无法使用 使用encodeURIComponent进行转义即可

js
const fileName = encodeURIComponent(res.headers['content-disposition'].split('filename=')[1]);

axios 在使用表单数据时会自动将header的content-type转换为 multipart/form-data

详见

  1. https://github.com/axios/axios#using-applicationx-www-form-urlencoded-format
  2. https://stackoverflow.com/questions/71412976/axios-converts-x-www-form-urlencoded-to-multipart-form-data

上次更新于: