Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Investigate require patch #12

Open
vicb opened this issue Sep 2, 2024 · 0 comments
Open

Investigate require patch #12

vicb opened this issue Sep 2, 2024 · 0 comments

Comments

@vicb
Copy link
Collaborator

vicb commented Sep 2, 2024

We currently have to patch require

https://github.com/dario-piotrowicz/poc-build-nextjs-app-for-cf-workers/blob/6cc9bf4a3e4b0c0673b0c9fac22912445baa734a/nextjs-worker-builder/src/build/build-worker/patches/investigated/patchRequire.ts

@jasnell implemented module.createRequire in cloudflare/workerd#2636

Looking at evanw/esbuild#1921, it looks like the banner can be updated to something similar to

import { createRequire } from 'module';
const require = createRequire(import.meta.url);

There are a few things to solve here:

  1. unenv

Screen Shot 2024-09-02 at 10 38 07 AM

unenv should only mock module when methods are not implemented - that is createRequire and isBuiltin should use the workerd implementation when it is present (/cc @pi0)

  1. workerd has no access to import.meta.url
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant