在Linux (CentOS)系统下,打包带prerender-spa-plugin 这个预渲染插件的内容,出现如下报错

 

Error: Failed to launch chrome!
/mnt/workspace/xxx/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: error while loading shared libraries: libXss.so.1: cannot open shared object file: No such file or directory
TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
    at onClose (/mnt/workspace/xxx/node_modules/puppeteer/lib/Launcher.js:348:14)
    at Interface.<anonymous> (/mnt/workspace/xxx/node_modules/puppeteer/lib/Launcher.js:337:50)
    at Interface.emit (events.js:327:22)
    at Interface.close (readline.js:416:8)
    at Socket.onend (readline.js:194:10)
    at Socket.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1220:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
[Prerenderer - PuppeteerRenderer] Unable to start Puppeteer
/mnt/workspace/xxx/scripts/uat.js:14
  throw err;
 TypeError: Cannot read property 'close' of null
    at PuppeteerRenderer.destroy (/mnt/workspace/xxx/node_modules/@prerenderer/renderer-puppeteer/es6/renderer.js:140:21)
    at Prerenderer.destroy (/mnt/workspace/xxx/node_modules/@prerenderer/prerenderer/es6/index.js:87:20)
    at /mnt/workspace//node_modules/prerender-spa-plugin/es6/index.js:144:29
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

  

解决方案如下:

1、确保 prerender-spa-plugin 配置中不包含headless 和 inject配置项

new PrerenderSPAPlugin({
              routes: ["/future"],
              staticDir: path.join(__dirname, '../build'),
              renderer: new Renderer({
                renderAfterTime: 5000
              })
            })

2、在Linux 系统下安装依赖包,命令如下:

yum install libXScrnSaver atk java-atk-wrapper at-spi2-atk gtk3 libXt -y