Windows10下Nuxt3构建后cookie-es模块因符号链接复制失效问题求解
问题描述
Nuxt 3构建后,cookie-es模块以符号链接(Windows下的引用形式)导出,复制后该引用会变为空目录。
问题诉求
如何让Nuxt将模块导出为标准目录(若可行)?或者在Windows下复制文件时,如何将引用替换为真实文件?
问题展示
- 构建完成后
....output\server\node_modules下的cookie-es模块为符号链接形式 - 复制到其他路径
otherPath....output\server\node_modules后,原符号链接变为空目录 - 该符号链接指向
node_modules/.nitro中的文件,复制后引用失效导致目录内容丢失
环境信息
- 操作系统:Windows 10
- Nuxt版本:^3.4.3
已尝试方案
- 在nuxt.config的vite配置中禁用符号链接:
vite: { resolve: { preserveSymlinks: false } }
- 手动将构建后的模块文件复制到缺失目录:可行但无法自动化操作
已实现的解决方案
通过在package.json中添加自动复制脚本解决问题:
"scripts": { "build": "nuxt build", "postbuild": "robocopy /e /j \".output/server/node_modules\" \".output/server/node_modules_copy\" & rd /s /q \".output/server/node_modules\" & robocopy /e /j \".output/server/node_modules_copy\" \".output/server/node_modules\" & rd /s /q \".output/server/node_modules_copy\"" }
脚本逻辑:将无符号链接的模块复制到新目录,再替换回原node_modules目录。
欢迎提供更优解决方案,感谢!
内容的提问来源于stack exchange,提问作者Jiří Žák
相关产品推荐
相关产品推荐

