Comments (3)
so, i was able to fix this. here is the solution in case anyone else comes across this problem.
in my case, it was because packages with a /
in the name were not being properly aliased. so when react-ab-test
was requiring react-dom/server
for their server render, it was not being aliased properly
i needed to add the following to my webpack server config (i got this from some other thread, can't remember):
let nodeModules = {}
fs.readdirSync('node_modules').forEach(function (module) {
if (module !== '.bin') {
nodeModules[module] = true;
}
})
const nodeModulesTransform = function(context, request, callback) {
// search for a '/' indicating a nested module
const slashIndex = request.indexOf("/");
let rootModuleName;
if (slashIndex == -1) {
rootModuleName = request;
} else {
rootModuleName = request.substr(0, slashIndex);
}
// Match for root modules that are in our node_modules
if (nodeModules.hasOwnProperty(rootModuleName)) {
callback(null, 'commonjs ' + request);
} else {
callback();
}
}
and then in your config object itself add this line:
externals: [nodeModulesTransform],
from preact-render-to-string.
@rossPatton That is usually caused by an alias not working - preact-render-to-string
is being passed a React element but it only supports Preact ones. How are you aliasing, and how are you running server-side?
Usually the common problem is that people alias in preact-compat
in their webpack config, but then their server-side setup actually imports things directly (ie, not using webpack). The solution is pretty simple, you just need to apply the same aliases from your webpack config to node's module loader itself via module-alias.
from preact-render-to-string.
i am using webpack ProvidePlugin like this:
new webpack.ProvidePlugin({
React: 'preact-compat',
ReactDOM: 'preact-compat',
ReactDOMServer: 'preact-render-to-string',
})
I use webpack for both my server and client builds (i bundle my server file) so I would assume that any aliases I set in webpack would be consistent on both the server and client side
Would this not be the case?
from preact-render-to-string.
Related Issues (20)
- 5.2.5 breaks server side rendering of @preact/signals HOT 2
- renderToString with {pretty: true} causes undesirable newlines with text nodes HOT 1
- Rendering asynchronous component throws an error HOT 9
- Meta charset not rendered as expected HOT 1
- Void elements have whitespace at closing
- Using effects from @preact/signals causes memory leak HOT 2
- CommonJS bundle broken for v6 HOT 1
- unpkg package seems failed HOT 2
- Unable to import shallowRender from preact-render-to-string/jsx due to TypeScript type errors
- preact and htm function does not return html when ssr rendered from mjs file HOT 3
- xlink:href becomes xlink::href
- `options._diff` not called for implicit Fragments HOT 2
- `preact/debug` warnings not thrown because `vnode.__k` is not set
- Stream Rendering Roadmap HOT 1
- Invalid nesting detection with `preact/debug` HOT 1
- Incorrect jsx type definition HOT 2
- HTML Entity encoding in Script Tags HOT 4
- renderToStringAsync seems to be unexported
- null is being removed when used as value in dangerouslySetInnerHTML html HOT 1
- Using @tanstack/react-query causes errors. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from preact-render-to-string.