wmr
wmr copied to clipboard
Build segfaults on Node.js v16 if config contains empty middleware array
Describe the bug
If config contains empty array of middlewares, wmr run build ends with segfault.
To Reproduce Steps to reproduce the behavior:
- Initialise new project with
npm init wmr@latest myproject,cdtomyproject - In
wmr.config.mjsaddmiddleware: []to config object Run npm run build- See error
Expected behavior Build finishes successfully
Bug occurs with:
- [ ]
wmrorwmr start(development) - [x]
wmr build(production) - [ ]
wmr serve
Desktop (please complete the following information):
- OS: Ubuntu 20.04.3
- Browser: N/A
- Node Version: 16.13.0; NPM Version: 8.1.2
- WMR Version: 3.7.2
Additional context
Sometimes build finishes fine if middleware is null or undefined but fails at random. When set to empty array build failed in 20/20 attempts.
Can you provide the error please?
I cannot reproduce, and I don't believe middlewares are used in any part of the build process.
This is segfault.
$ 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
Segmentation fault (core dumped)
Config that does not segfault:
import { defineConfig } from 'wmr';
// Full list of options: https://wmr.dev/docs/configuration
export default defineConfig({
/* Your configuration here */
alias: {
react: 'preact/compat',
'react-dom': 'preact/compat'
}
});
Config that segfaults always:
import { defineConfig } from 'wmr';
// Full list of options: https://wmr.dev/docs/configuration
export default defineConfig({
/* Your configuration here */
alias: {
react: 'preact/compat',
'react-dom': 'preact/compat'
},
middleware: []
});
If middleware is null then segfaults happen at random.
That's really interesting. Can you share the debug info? wmr build --debug
And on Mac OS 11.6.1 (node & npm versions exactly as on my Linux box):
$ 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.8a0cfff0.js 17Kb
dist/assets/style.e6ee4bcf.css 499b
dist/chunks/prerender.c8def485.js 4.8Kb
dist/chunks/index.a1e0eb1d.js 214b
Segmentation fault: 11
Debug output from MacOS:
$ node_modules/.bin/wmr build --prerender --debug
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
wmr:config {
wmr:config _: [],
wmr:config prerender: true,
wmr:config debug: true,
wmr:config cwd: '/Users/jarekzgoda/work/test0',
wmr:config public: 'public',
wmr:config out: '/Users/jarekzgoda/work/test0/dist',
wmr:config sourcemap: undefined,
wmr:config visualize: undefined,
wmr:config minify: true,
wmr:config root: '/Users/jarekzgoda/work/test0/public',
wmr:config plugins: [],
wmr:config output: [],
wmr:config middleware: [],
wmr:config features: { preact: true },
wmr:config alias: { react: 'preact/compat', 'react-dom': 'preact/compat' },
wmr:config customRoutes: [],
wmr:config prod: true,
wmr:config mode: 'build',
wmr:config env: {},
wmr:config overlayDir: '/Users/jarekzgoda/work/test0/dist',
wmr:config publicPath: '/',
wmr:config host: 'localhost'
wmr:config }
npm:plugin htm/preact -> npm/[email protected]/preact/index.module.js
npm:plugin preact-iso -> npm/[email protected]/index.js
npm:plugin htm/preact -> npm/[email protected]/preact/index.module.js
npm:plugin htm/preact -> npm/[email protected]/preact/index.module.js
npm:plugin htm/preact -> npm/[email protected]/preact/index.module.js
npm:plugin preact-iso -> npm/[email protected]/index.js
npm:plugin preact/hooks -> npm/[email protected]/hooks/dist/hooks.module.js
npm:plugin htm/preact -> npm/[email protected]/preact/index.module.js
npm:plugin preact -> npm/[email protected]/dist/preact.module.js
npm:plugin htm -> npm/[email protected]/dist/htm.module.js
npm:plugin ./router.js -> npm/[email protected]/router.js
npm:plugin ./lazy.js -> npm/[email protected]/lazy.js
npm:plugin ./hydrate.js -> npm/[email protected]/hydrate.js
npm:plugin ./prerender.js -> npm/[email protected]/prerender.js
npm:plugin preact -> npm/[email protected]/dist/preact.module.js
npm:plugin preact -> npm/[email protected]/dist/preact.module.js
npm:plugin preact -> npm/[email protected]/dist/preact.module.js
npm:plugin preact -> npm/[email protected]/dist/preact.module.js
npm:plugin preact/hooks -> npm/[email protected]/hooks/dist/hooks.module.js
npm:plugin preact -> npm/[email protected]/dist/preact.module.js
npm:plugin preact/hooks -> npm/[email protected]/hooks/dist/hooks.module.js
npm:plugin preact-render-to-string -> npm/[email protected]/dist/index.mjs
npm:plugin preact -> npm/[email protected]/dist/preact.module.js
(!) minify(index.d5d2e732.js) took 200ms
Merging assets/style.module.83820528.css into assets/style.module.7b16dcc3.css (chunks/index.fb97a71f.js → index.d5d2e732.js)
Hoisting CSS "assets/style.module.7b16dcc3.css" imported by index.d5d2e732.js into parent HTML import "assets/style.e6ee4bcf.css".
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
Segmentation fault: 11
Downgraded node to v14.18.1 and everything works fine again.
Just wanted to comment that I too encountered some bizarre segfaults with Node 16, though it was entirely inconsistent and would occur seemingly post-prerender?
Output would be generated just fine, but 50% of the time I'd be hit with a lovely SIGSEGV before completion. Rerunning the build nearly always completed without any error.
Downgraded back to Node 14 too, no issues here. Really weird.
Edit: No config from me, so shouldn't be related to that in any way. Will try to track this down when I have some time, could just be buggy Node I suppose?
I've seen less of segfaults after upgrading npm to some later version, 8.1.2 or 8.1.3.
Interesting. Yarn for me, though did have latest NPM (8.1.3).
I think this is a duplicate issue: https://github.com/preactjs/wmr/issues/896#issuecomment-1004407280
I too am experiencing the random segmentation fault that prevents WMR prerender build from completing (missing HTML files in dist folder, and segfault in console). I am on MacOS, Node version 16.13.1, NPM version 8.3.0.
...I should also point out that WMR config.middleware: [] doesn't yield 100% repro, it seems as random as config.middleware: undefined or config.middleware: null.
Yes, it seems I was too quick assuming there's any relation.
Should we close this as a duplicate of #896?
I can reproduce this on wmr, 3.8.0 by just
yarn create wmr hello-preact-wmr
yarn build
It's 60-70% chance to get SIGSEGV (this one hit at first try, i'm feeling lucky)
katopz@fox hello-preact-wmr % yarn build
yarn run v1.22.17
$ wmr build --prerender
Wrote 27Kb to disk:
dist/index.html 460b
dist/index.32c06713.js 18Kb
dist/assets/style.e6ee4bcf.css 499b
dist/chunks/prerender.e1448b15.js 8.1Kb
dist/chunks/index.08589ee3.js 214b
error Command failed with signal "SIGSEGV".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
katopz@fox hello-preact-wmr % node --version && npm --version
v16.13.0
8.5.0
Not sure what the root cause is.