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

Prerendering not working on Node 16 #896

Open
1 of 3 tasks
Brawl345 opened this issue Nov 17, 2021 · 13 comments
Open
1 of 3 tasks

Prerendering not working on Node 16 #896

Brawl345 opened this issue Nov 17, 2021 · 13 comments
Labels
bug Something isn't working

Comments

@Brawl345
Copy link

Describe the bug
When running prerender on Node 16, the pages don't get prerendered.

To Reproduce
Steps to reproduce the behavior:

  1. Install Node 16
  2. Clone the example project: npm init wmr example && cd example
  3. Run npm run build (which in turn runs wmr build --prerender)

Expected behavior
The page should get prerendered and the resulting HTML should contain everything. This is the build output:

$ npm run build

> build
> wmr build --prerender

Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating

Wrote 23Kb to disk:
  dist\index.html 460b
  dist\index.d5d2e732.js 17Kb
  dist\assets/style.e6ee4bcf.css 499b
  dist\chunks/prerender.ea3dab95.js 4.8Kb
  dist\chunks/index.fb97a71f.js 214b

This is the resulting dist/index.html:

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>WMR App</title>
		<meta name="description" content="WMR App">
		<meta name="viewport" content="width=device-width,initial-scale=1">
		<link rel="icon" href="data:">
		<link rel="modulepreload" as="script" href="/index.d5d2e732.js">
		<link rel="stylesheet" href="/assets/style.e6ee4bcf.css">
	</head>
	<body>
		<script type="module" src="/index.d5d2e732.js"></script>
	</body>
</html>

Now the same on Node 14:


> @ build C:\Users\some\path\example-project
> wmr build --prerender

Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating

Wrote 23Kb to disk:
  dist\index.html 460b
  dist\index.d5d2e732.js 17Kb
  dist\assets/style.e6ee4bcf.css 499b
  dist\chunks/prerender.ea3dab95.js 4.8Kb
  dist\chunks/index.fb97a71f.js 214b
Prerendered 3 pages:
  /
  /about [from /]
  /error [from /]

You can see that it prerenders. The resulting index.html is correct:

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>WMR App</title>
		<meta name="description" content="WMR App">
		<meta name="viewport" content="width=device-width,initial-scale=1">
		<link rel="icon" href="data:">
		<link rel="modulepreload" as="script" href="/index.d5d2e732.js">
		<link rel="stylesheet" href="/assets/style.e6ee4bcf.css">
	</head>
	<body><div class="app"><header><nav><a href="/">Home</a><a href="/about">About</a><a href="/error">Error</a></nav><label> URL: <input readonly value="/" /></label></header><section class="home_7pwwsk"><h1>Home</h1><p>This is the home page.</p><button style="width: 30px;"> - </button><output style="padding: 10px;">Count: 0</output><button style="width: 30px;"> + </button></section></div>
		<script type="module" src="/index.d5d2e732.js"></script>
	</body>
</html>

Bug occurs with:

  • wmr or wmr start (development)
  • wmr build (production)
  • wmr serve

Desktop (please complete the following information):

  • OS: Windows 8.1
  • Browser: N/A
  • Node Version: v16.13.0
  • WMR Version: 3.7.2

Additional context
N/A

@Brawl345 Brawl345 added the bug Something isn't working label Nov 17, 2021
@zgoda
Copy link

zgoda commented Nov 21, 2021

Check if the build segfaults, this might be the same issue as #893

@Brawl345
Copy link
Author

No segfault, but I'm on Windows.

C:\Users\xyz\Downloads\example>npm run build

> build
> wmr build --prerender

Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating

Wrote 23Kb to disk:
  dist\index.html 460b
  dist\index.d5d2e732.js 17Kb
  dist\assets/style.e6ee4bcf.css 499b
  dist\chunks/prerender.ea3dab95.js 4.8Kb
  dist\chunks/index.fb97a71f.js 214b

@danielweck
Copy link

I experience a random segmentation fault on MacOS during WMR build (prerender) with Node version 16.13.1. Same symptom as the original poster of this issue #896 (Windows user, no segfault visible in the console).
This appears to be the same problem reported in #893

@danielweck
Copy link

Update: in addition to segfault fatal exit codes, I am also getting graceful exit codes but the pre-rendering pass just stops without handing over to my post-build process. Very strange bug, which occurs frequently locally on my dev computer (MacOS), as well as CloudFlare Pages builder, and GitHub Actions CI. Could this have anything to do with Preact WMR's NodeJS Worker used to invoke the prerender script?

@developit
Copy link
Member

developit commented Jan 19, 2022

@danielweck yes, I think this is related to our use of worker_threads. I'm thinking it may be the Node/glibc bug described here.

What type of Nodejs installation are you using on MacOS? I notice this started when I updated to 16.13.1, but I'm not sure if the brew/nvm binaries have the same issue (perhaps they're linked against different versions of glibc?).

@danielweck
Copy link

Thanks Jason.
node --version => v16.13.2
Installed on MacOS via https://nodejs.org

@danielweck
Copy link

Ah Ah, I am using this package.json script for my CI builds now:

"build-try-again-if-fail": "(npm run build || npm run build || npm run build || npm run build || npm run build || npm run build || npm run build || npm run build || npm run build || npm run build || exit 0) || echo OK"

Ugly, but "60% of the time, it works every time" 👍

@lPadier
Copy link
Contributor

lPadier commented Jan 21, 2022

I've reproduced build failures for a default project npm init wmr on the following platforms:

  • Linux aarch64 (Raspberry Pi 4 (docker node:16, node:16-alpine)
  • macOS aarch64 (M1 native (installed with tj/n) and in docker)
  • Windows x86_64
  • Linux x86_64 (docker node:16, node:16-alpine)

macOS M1

Running the build 100 times on the following versions fails n times:

Version Failures
16.5.0 0,0
16.6.0 0,0,0
16.7.0 0,2
16.8.0 2,2
16.9.0 9
16.10.0 2,7,9,1
16.11.0 16,31,11,16,12
16.13.1 16,20

Running build 10_000 times on the following versions fails n times:

Version Failures
16.5.0 0
16.6.0 3
16.13.1 3287
17.0.0 0

I ran the build twice for 16.5.0.

docker:16 images use debian buster and this glibc:

GNU C Library (Debian GLIBC 2.28-10) stable release version 2.28.

edit

I've also reproduced this on node:16-bullseye-slim

GNU C Library (Debian GLIBC 2.31-13+deb11u2) stable release version 2.31.

@rschristian
Copy link
Member

For what it's worth I can no longer reproduce the segfaults. Whatever bug in Node was causing them seems to be resolved?

Personally on Node v16.16.0

@Brawl345
Copy link
Author

Can confirm on Node v16.17.0 on Windows 10 x64:

> npm run build

> build
> wmr build --prerender

Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating
Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db
  Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating

Wrote 27Kb to disk:
  dist\index.html 460b
  dist\index.883c8e44.js 18Kb
  dist\assets/style.e6ee4bcf.css 499b
  dist\chunks/prerender.ef8ef4be.js 7.7Kb
  dist\chunks/index.7fb9d5bb.js 214b
Prerendered 3 pages:
  /
  /about [from /]
  /error [from /]

@rschristian
Copy link
Member

I've ran the CI a few times in the past few days too, haven't ran into it.

I'm going to tentatively say this is resolved and close it out. If anyone runs into issues feel free to reply and we can reopen.

@PodaruDragos
Copy link

PodaruDragos commented Nov 21, 2022

Hello, running into the same problem maybe

On a fresh new project on a windows machine.

$ npm --version
8.19.2

$ node --version
v19.0.0

$ npm run build --prerender

> build
> wmr build --prerender

Wrote 27Kb to disk:
  dist\index.html 460b
  dist\index.4b7b983c.js 18Kb
  dist\assets/style.e6ee4bcf.css 499b
  dist\chunks/prerender.6b2475ca.js 8.1Kb
  dist\chunks/index.0e61ca1c.js 214b
/path_to_node_js_/npm: line 44:  1746 Segmentation fault  "$NODE_EXE" "$NPM_CLI_JS" "$@"

@rschristian
Copy link
Member

@PodaruDragos Indeed, unfortunately we've noticed this too.

@rschristian rschristian reopened this Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants