-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Trying to mess with ServerComponentsPlugin
, hitting error
#3997
Comments
(issue reproduces in 0.8.0) |
Tried to do the same and hit the same issue. After digging a bit, it appears that server components are not supported since the introduction of a new bundler: #2312 If you look at the JSBundler code, here is the line that causes the error: Edit: I was wrong regarding the fact it's not supported. After a few hours investigating, here is how I got to the "read the manifest" part: import {ByteBuffer} from 'peechy/bb';
import * as path from 'path';
import ServerComponentsPlugin from 'bun-plugin-server-components';
import {renderToReadableStream} from 'react-dom/server';
const PROJECT_ROOT = import.meta.dir;
const PAGE_DIR = path.resolve(PROJECT_ROOT, 'pages');
const PUBLIC_DIR = path.resolve(PROJECT_ROOT, 'public');
const BUILD_DIR = path.resolve(PROJECT_ROOT, '.build');
const srcRouter = new Bun.FileSystemRouter({
dir: PAGE_DIR,
style: 'nextjs',
});
const buildResult = await Bun.build({
entrypoints: [
...Object.values(srcRouter.routes),
],
outdir: BUILD_DIR,
manifest: true,
plugins: [
ServerComponentsPlugin({
directive: {
client: [''],
server: [''],
},
}),
],
});
function decodeStringPointer(bb: ByteBuffer) {
let result: any = {};
result['offset'] = bb.readUint32();
result['length'] = bb.readUint32();
return result;
}
function decodeClientServerModule(bb: ByteBuffer) {
const result: any = {};
result['moduleId'] = bb.readUint32();
result['inputName'] = decodeStringPointer(bb);
result['assetName'] = decodeStringPointer(bb);
result['exportNames'] = decodeStringPointer(bb);
return result;
}
function decodeClientServerModuleManifest(bb: ByteBuffer) {
const result: any = {};
result['version'] = bb.readUint32();
let length = bb.readVarUint();
let values = (result['clientModules'] = Array(length));
for (let i = 0; i < length; i++) values[i] = decodeClientServerModule(bb);
length = bb.readVarUint();
values = result['serverModules'] = Array(length);
for (let i = 0; i < length; i++) values[i] = decodeClientServerModule(bb);
length = bb.readVarUint();
values = result['ssrModules'] = Array(length);
for (let i = 0; i < length; i++) values[i] = decodeClientServerModule(bb);
length = bb.readVarUint();
values = result['exportNames'] = Array(length);
for (let i = 0; i < length; i++) values[i] = decodeStringPointer(bb);
result['contents'] = bb.readByteArray();
return result;
}
const manifestBuffer = new Uint8Array(await Bun.file(buildResult.outputs[2].path).arrayBuffer());
let manifest = new ByteBuffer(manifestBuffer);
const decoded = decodeClientServerModuleManifest(manifest);
console.log(decoded); Now I have no idea what the "directive" options are for, and I guess this is all too experimental for now, but it's nice to see it's not that far away. Anyway, SSR will amply do for now :) |
Same issue with |
What version of Bun is running?
0.7.0
What platform is your computer?
Darwin 22.5.0 arm64 arm
What steps can reproduce the bug?
Try to run this script:
Gives this error:
The location seems to be a red herring. I only get this error when trying to use the
ServerComponentsPlugin
plugin. For example, this works without error:What is the expected behavior?
Code runs cleanly with no errors
What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: