next-bun-compile 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -77,6 +77,29 @@ The binary is fully self-contained — static assets, public files, and the Next
77
77
 
78
78
  Some modules can't be resolved at compile time but are never reached in production (dev servers, optional dependencies). The adapter creates no-op stubs for these **only if** the real module isn't installed. If you actually use `@opentelemetry/api` or `critters`, the real package gets bundled instead.
79
79
 
80
+ ## Troubleshooting
81
+
82
+ ### Packages with dynamic `require()` calls (e.g. pino)
83
+
84
+ Some packages like `pino` use dynamic `require()` calls internally (for worker threads, transports, etc.). Turbopack can't resolve these at build time, so they fail at runtime inside the compiled binary with errors like:
85
+
86
+ ```
87
+ Failed to load external module pino-142500b1eb3f4baf: Cannot find package ...
88
+ ```
89
+
90
+ **Fix:** Add the package to `transpilePackages` in your `next.config.ts`:
91
+
92
+ ```ts
93
+ const nextConfig: NextConfig = {
94
+ transpilePackages: ["pino", "pino-pretty"],
95
+ experimental: {
96
+ adapterPath: require.resolve("next-bun-compile"),
97
+ },
98
+ };
99
+ ```
100
+
101
+ This forces Turbopack to fully compile the package source rather than deferring dynamic requires to runtime.
102
+
80
103
  ## Support
81
104
 
82
105
  If this saved you time, consider supporting the project:
package/dist/index.js CHANGED
@@ -179,13 +179,21 @@ function compile(options) {
179
179
 
180
180
  // src/index.ts
181
181
  import { join as join3 } from "node:path";
182
+ var knownTranspilePackages = ["pino", "pino-pretty"];
182
183
  var adapter = {
183
184
  name: "next-bun-compile",
184
- modifyConfig(config) {
185
+ modifyConfig(config, { phase }) {
186
+ if (phase !== "phase-production-build")
187
+ return config;
185
188
  if (config.output !== "standalone") {
186
189
  console.warn('next-bun-compile: Setting output to "standalone" (required for compilation)');
187
190
  config.output = "standalone";
188
191
  }
192
+ const existing = config.transpilePackages ?? [];
193
+ const toAdd = knownTranspilePackages.filter((p) => !existing.includes(p));
194
+ if (toAdd.length > 0) {
195
+ config.transpilePackages = [...existing, ...toAdd];
196
+ }
189
197
  return config;
190
198
  },
191
199
  async onBuildComplete(ctx) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-bun-compile",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Next.js Build Adapter that compiles your app into a Bun single-file executable",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",