Skip to content

Instantly share code, notes, and snippets.

@3846masa
Last active July 9, 2024 10:29
Show Gist options
  • Save 3846masa/bb3ade18b8a16d947f85920640ab35a2 to your computer and use it in GitHub Desktop.
Save 3846masa/bb3ade18b8a16d947f85920640ab35a2 to your computer and use it in GitHub Desktop.

Code that reproduces the bug

Usage

npm install
npm run build
npm start

Actual

ReferenceError: renderToPipeableStream is not defined
    at ./node_modules/preact/compat/server.mjs (/Users/xxx/gist.github.com/bb3ade18b8a16d947f85920640ab35a2/bundle.cjs:139:2)
    at __webpack_require__ (/Users/xxx/gist.github.com/bb3ade18b8a16d947f85920640ab35a2/bundle.cjs:165:41)
    at /Users/xxx/gist.github.com/bb3ade18b8a16d947f85920640ab35a2/bundle.cjs:76:74
    at __webpack_require__.a (/Users/xxx/gist.github.com/bb3ade18b8a16d947f85920640ab35a2/bundle.cjs:222:13)
    at ./index.mjs (/Users/xxx/gist.github.com/bb3ade18b8a16d947f85920640ab35a2/bundle.cjs:71:21)
    at __webpack_require__ (/Users/xxx/gist.github.com/bb3ade18b8a16d947f85920640ab35a2/bundle.cjs:165:41)
    at /Users/xxx/gist.github.com/bb3ade18b8a16d947f85920640ab35a2/bundle.cjs:274:37
    at Object.<anonymous> (/Users/xxx/gist.github.com/bb3ade18b8a16d947f85920640ab35a2/bundle.cjs:276:12)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)

Expected

<h1>Hello Preact!</h1>
/node_modules
/bundle.*
/package-lock.json
import { PassThrough } from 'node:stream';
import { text } from 'node:stream/consumers';
import { jsx } from 'react/jsx-runtime';
import { renderToPipeableStream } from 'react-dom/server';
const element = jsx('h1', { children: 'Hello, Preact!' });
const stream = new PassThrough();
renderToPipeableStream(element, {}).pipe(stream);
const html = await text(stream);
console.log(html);
{
"scripts": {
"build": "webpack",
"start": "node bundle.cjs"
},
"dependencies": {
"preact": "10.22.1",
"preact-render-to-string": "6.5.5"
},
"devDependencies": {
"webpack": "5.92.1",
"webpack-cli": "5.1.4",
"webpack-node-externals": "3.0.0"
}
}
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import nodeExternals from 'webpack-node-externals';
/** @type {import('webpack').Configuration} */
export default {
mode: 'development',
entry: './index.mjs',
output: {
path: dirname(fileURLToPath(import.meta.url)),
filename: './bundle.cjs',
},
target: 'node',
externals: [nodeExternals()],
resolve: {
alias: {
react: 'preact/compat',
'react-dom/test-utils': 'preact/test-utils',
'react-dom': 'preact/compat',
},
},
devtool: 'source-map',
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment