-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix build issues with
@opentelemetry
(#302)
- Loading branch information
Showing
7 changed files
with
329 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@opennextjs/cloudflare": patch | ||
--- | ||
|
||
fix build issues with `@opentelemetry` | ||
|
||
By using the pre-compiled library provided by Next. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/cloudflare/src/cli/build/patches/plugins/require.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import fs from "node:fs/promises"; | ||
|
||
import type { PluginBuild } from "esbuild"; | ||
|
||
export default function fixRequire() { | ||
return { | ||
name: "fix-require", | ||
|
||
setup: async (build: PluginBuild) => { | ||
build.onLoad({ filter: /.*/ }, async ({ path }) => { | ||
let contents = await fs.readFile(path, "utf-8"); | ||
|
||
// `eval(...)` is not supported by workerd. | ||
contents = contents.replaceAll(`eval("require")`, "require"); | ||
|
||
// `@opentelemetry` has a few issues. | ||
// | ||
// Next.js has the following code in `next/dist/server/lib/trace/tracer.js`: | ||
// | ||
// try { | ||
// api = require('@opentelemetry/api'); | ||
// } catch (err) { | ||
// api = require('next/dist/compiled/@opentelemetry/api'); | ||
// } | ||
// | ||
// The intent is to allow users to install their own version of `@opentelemetry/api`. | ||
// | ||
// The problem is that even when users do not explicitely install `@opentelemetry/api`, | ||
// `require('@opentelemetry/api')` resolves to the package which is a dependency | ||
// of Next. | ||
// | ||
// The second problem is that when Next traces files, it would not copy the `api/build/esm` | ||
// folder (used by the `module` conditions in package.json) it would only copy `api/build/src`. | ||
// This could be solved by updating the next config: | ||
// | ||
// const nextConfig: NextConfig = { | ||
// // ... | ||
// outputFileTracingIncludes: { | ||
// "*": ["./node_modules/@opentelemetry/api/build/**/*"], | ||
// }, | ||
// }; | ||
// | ||
// We can consider doing that when we want to enable users to install their own version | ||
// of `@opentelemetry/api`. For now we simply use the pre-compiled version. | ||
contents = contents.replace( | ||
/require\(.@opentelemetry\/api.\)/g, | ||
`require("next/dist/compiled/@opentelemetry/api")` | ||
); | ||
|
||
return { contents }; | ||
}); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
packages/cloudflare/src/cli/build/patches/to-investigate/wrangler-deps.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.