preactjs / wmr

👩‍🚀 The tiny all-in-one development tool for modern web apps.
https://wmr.dev/
MIT License
4.93k stars 110 forks source link

Prerendering not working on Node 16 #896

Open Brawl345 opened 2 years ago

Brawl345 commented 2 years ago

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:

Desktop (please complete the following information):

Additional context N/A

zgoda commented 2 years ago

Check if the build segfaults, this might be the same issue as https://github.com/preactjs/wmr/issues/893

Brawl345 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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

danielweck commented 2 years ago

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 commented 2 years ago

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

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

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