-
Notifications
You must be signed in to change notification settings - Fork 45
fix build issues with @opentelemetry
#302
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.