pkg打包nestjs项目问题点整理

  1. 打包运行过程中的警告
    Warning Cannot include directory %1 into executable.
    The directory must be distributed with executable as %2.
    %1: node_modules\puppeteer.local-chromium
    %2: path-to-executable/puppeteer
    在这里插入图片描述
    解决方法:
    警告大义为在路径如%1的某个目录、某个文件必须分配到exe文件的同一目录下,路径如%2,但是我按照warning手动复制目录、文件仍无效,如果有童鞋有效果!麻烦指导我一下!最终我只能为使用到这些目录、文件的代码,指定使用路径,比如puppeteer,修改路径为:
executablePath: join(process.cwd(), 'puppeteer/win64-901912/chrome-win/chrome.exe')

因为pkg打包生成的exe运行后,会给__dirname等路径前加上一个临时目录:/snapshot/__dirname,而运行目录process.cwd(),process.execPath不会,我这边用了process.execPath作为相对定位;
xdg-open没有找到使用的地方,没管它也没报错;

  1. exe执行文件运行闪退
    通过cmd界面,运行exe执行文件,可以看到错误信息显示如下:
    pkg/prelude/bootstrap.js:1872
    throw error;
    Error: File ‘C:**\rh-design-print\node_modules\vm2\lib\setup-sandbox.js’ was not included into executable at compilation stage. Please recompile adding it as asset or script.
    在这里插入图片描述
    解决方法:
    一开始我用了傻办法,把整个node_modules都打包进去,成功了,但是exe文件逼近1g,巨大无比;
    后来发现,只把报错的这个库打包进去,也行,配置如下:
"pkg": {
        "assets": [
            "node_modules/vm2"
        ],
        "outputPath": "dist/",
        "targets": [
            "node14-win-x64"
        ]
    }

如果还是解决不了闪退问题,考虑把整个node_modules打包进去:

"pkg": {
        "assets": [
            "node_modules"
        ],
        "outputPath": "dist/",
        "targets": [
            "node14-win-x64"
        ]
    }
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值