Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby-plugin-preload-fonts] Make puppeteer script compatible with Alpine #21778

Closed
nibtime opened this issue Feb 26, 2020 · 4 comments · Fixed by #21845
Closed

[gatsby-plugin-preload-fonts] Make puppeteer script compatible with Alpine #21778

nibtime opened this issue Feb 26, 2020 · 4 comments · Fixed by #21845

Comments

@nibtime
Copy link
Contributor

nibtime commented Feb 26, 2020

Summary

I installed gatsby-plugin-preload-fonts and tried to start the crawler script. I got some output that looked like this:

Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: gnu_get_libc_version: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: __fdelt_chk: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: backtrace: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: __strncat_chk: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: __fprintf_chk: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: __sprintf_chk: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: initstate_r: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: random_r: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: getcontext: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: __isinff: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: __vfprintf_chk: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: __register_atfork: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: __longjmp_chk: symbol not found
Error relocating /workspaces/iacm-site/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: __libc_stack_end: symbol not found

I am developing with Gatsby inside a VS Code Remote Container based on Alpine. The problem seems to be, that puppeteer does not download a musl version of Chromium. I've installed Chromium for Alpine though, but puppeteer does not use it.

The problem could be mitigated by making the executablePath of puppeteer.launch a parameter of the script.

Basic example

Puppeteer can be pointed to the correct Chromium path (see here)

To work around the problem, I made the following replacement: in prepare/index.js in the node_modules folder:

  const browser = await puppeteer.launch({
    args: process.argv.slice(2)
  });
const browser = await puppeteer.launch({
    executablePath: '/usr/bin/chromium-browser',
    args: process.argv.slice(2)
  });

Motivation

This would make the plugin usable with Alpine Linux. Also I think this should be documented somehow, even if it is just this issue.

@nibtime
Copy link
Contributor Author

nibtime commented Feb 27, 2020

The following code makes it possible to set executablePath for Chromium when executing the script. Could send a PR if this is desired.

Allows to start script like this:
npm run gatsby-preload-fonts executable-path=/usr/bin/chromium-browser --no-sandbox --headless --disable-gpu

  const processArgs = process.argv.slice(2)
  const isExecutablePathArg = arg => arg.includes("executable-path")
  const executablePathArg = processArgs.find(isExecutablePathArg)
  const [,executablePath] = executablePathArg ? executablePathArg.split("=") : [undefined, undefined]
  const args = processArgs.filter(arg => !isExecutablePathArg(arg))
  const browser = await puppeteer.launch({
    executablePath,
    args
  });

@acao
Copy link
Contributor

acao commented Feb 27, 2020

hello @nibtime, excellent work, thank you!
a PR for this fix would be great to have

@pieh
Copy link
Contributor

pieh commented Feb 27, 2020

According to those docs: https://pptr.dev/#?product=Puppeteer&version=v1.20.0&show=api-environment-variables you should be able to use PUPPETEER_EXECUTABLE_PATH env var and that wouldn't require any code changes (but could be documented in the README.md if that works)

(docs for [email protected] because that's version we use in the plugin -

- in 2.x.x line it also seem supported)

@nibtime
Copy link
Contributor Author

nibtime commented Feb 28, 2020

Thanks @pieh, that works!
A code change is not necessary then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants