changeset 报错 Cannot read properties of null (reading ‘prerelease’)

chat

执行 pnpm changeset version,如果 changeset 报错 Cannot read properties of null (reading 'prerelease')

参考:https://github.com/changesets/changesets/issues/835

解决办法:进入报错堆栈第一行对应文件所在代码行,添加?.可选链

let preVersion = parsed?.prerelease?.[1] === undefined ? -1 : parsed?.prerelease?.[1];

可以在构建脚本加上自动替换代码

# 替换存在问题的文件  参考:https://github.com/changesets/changesets/issues/835
FILE_PATH="./node_modules/.pnpm/@changesets+assemble-release-plan@6.0.5/node_modules/@changesets/assemble-release-plan/dist/changesets-assemble-release-plan.cjs.js"
if [ -f "$FILE_PATH" ]; then
    sed -i.bak 's/parsed.prerelease[1] === undefined ? -1 : parsed.prerelease[1];/parsed?.prerelease?.[1] === undefined ? -1 : parsed?.prerelease?.[1];/g' "$FILE_PATH"
    echo "替换完成。备份文件已保存为 ${FILE_PATH}.bak"
else
    echo "文件 $FILE_PATH 不存在。"
fi
本文通过 YUQUE WORDPRESS 同步自语雀

版权声明:
作者:东明兄
链接:https://blog.crazyming.com/note/3235/
来源:CrazyMing
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
海报
changeset 报错 Cannot read properties of null (reading ‘prerelease’)
执行 pnpm changeset version,如果 changeset 报错 Cannot read properties of null (reading 'prerelease'), 参考:https://github.com/changesets/changes……
<<上一篇
下一篇>>
chat