Skip to content
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

Intermittent Errors with Bun.build and Bun.FileSystemRouter when importing absolute paths #9517

Open
antimatter15 opened this issue Mar 19, 2024 · 0 comments
Labels
bug Something isn't working bun.js Something to do with a Bun-specific API needs investigate Needs to be investigated to find the root cause

Comments

@antimatter15
Copy link

antimatter15 commented Mar 19, 2024

What version of Bun is running?

1.0.33+9e91e137f

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

This is a pretty basic server that returns the result of Bun.build on _entry.tsx

const router = new Bun.FileSystemRouter({
	style: "nextjs",
	dir: "./pages",
});

const server = Bun.serve({
	port: 3000,
	async fetch(req) {
		const result = await Bun.build({
			entrypoints: ['./pages/_entry.tsx'],
		});
		if (!result.success) {
			return new Response(JSON.stringify(result.logs
				.map((k) => Bun.inspect(k))
				.join("\n")));
		}
		return new Response(result.outputs.find(k => k.kind === 'entry-point'))
	}
});

With this _entry.tsx, it works fine

import ReactDOM from "react-dom/client";
import PageComponent from "./index.tsx";

ReactDOM.createRoot(document.getElementById("root")!).render(<PageComponent />);

But if the PageComponent import is an absolute path instead, the server has intermittent errors

import PageComponent from "/Users/kevin/Github/bun-dle/index.tsx";

It works the first time, but subsequent reloads sometimes have errors like:

error: Unexpected reading file: \"/Users/kevin/Github/bun-dle/pages/index.tsx\"\n    at /Users/kevin/Github/bun-dle/pages/index.tsx
error: Unexpected reading file: \"/Users/kevin/Github/bun-dle/node_modules/react/jsx-dev-runtime.js\"\n    at /Users/kevin/Github/bun-dle/node_modules/react/jsx-dev-runtime.js\n6 |   module.exports = require('./cjs/react-jsx-dev-runtime.development.js');\n                               ^\nerror: Could not resolve: \"./cjs/react-jsx-dev-runtime.development.js\"\n    at /Users/kevin/Github/bun-dle/pages/index.tsx:6:28
error: NotOpenForReading reading file: \"/Users/kevin/Github/bun-dle/node_modules/react-dom/client.js\"\n    at /Users/kevin/Github/bun-dle/node_modules/react-dom/client.js

This seems to depend on the presence of FileSystemRouter. If we remove the FileSystemRouter then it works reliably.

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

@antimatter15 antimatter15 added the bug Something isn't working label Mar 19, 2024
@Electroid Electroid added bun.js Something to do with a Bun-specific API needs investigate Needs to be investigated to find the root cause labels Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun.js Something to do with a Bun-specific API needs investigate Needs to be investigated to find the root cause
Projects
None yet
Development

No branches or pull requests

2 participants