-
Notifications
You must be signed in to change notification settings - Fork 28.3k
Truly dynamic imports with Turbopack, i.e. support for Monaco editor #72613
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
Comments
I believe the examples label has been added by mistake. I don't think I can remove it. |
If you are using pnpm, you can patch the monaco-editor.
The only issue is that the editor will not have syntax highlighting when running next.js in dev mode. The turbopack team said that they will be migrating the most popular webpack plugins to turbopack once they reach stable, so lets hope that |
They don't have to add support for plugins, they just need to relax the rewriting rule for truly dynamic imports. It should not be failing for something that can be resolved at runtime (maybe emit a warning but not hard stop error), it's on me to provide the adequate workaround. It's just a matter of mapping entry points to chunks. That's all there's to this. I've done this before but here I find Turbopack missing a critical feature. It's just overly zealous about rewriting some imports. |
I opted to do this instead: This way, when I want to work with monaco editor, I can run without --turbo. |
Hey! Having the same issue. Any updates or workarounds other than patching |
This comment has been minimized.
This comment has been minimized.
Could you share a full reproduction repository? I.e. "use client";
import Editor from "@monaco-editor/react";
export default function IDE() {
const handleSubmit = async () => {};
return (
<div className="flex justify-center items-start pt-10 h-screen">
<div className="w-full max-w-4xl p-4 border">
<form action="#" onSubmit={handleSubmit}>
<div className="">
<label htmlFor="comment" className="sr-only">
Add your code
</label>
<Editor
height="50vh"
defaultLanguage="javascript"
defaultValue='Deno.serve(req => new Response("Hello!"));'
/>
</div>
<div className="flex justify-between pt-2">
<div className="flex items-center space-x-5"></div>
<div className="flex-shrink-0">
<button
type="submit"
className="inline-flex items-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white hover:bg-indigo-500"
>
Run
</button>
</div>
</div>
</form>
</div>
</div>
);
} |
I don't know that it does. The problem really is with the way Next takes control over the rewriting of imports without leaving you with any option to bail. All I want, is to be able to use Monaco directly without libraries and workarounds. For that to be possible I need to be able to tell Next to not touch the import that does the bootstrapping for Monaco. I'm perfectly happy with vendoring the libraries. In my particular situation, a CDN is also out of the question. |
Verify canary release
Provide environment information
Operating System: Platform: win32 Arch: x64 Version: Windows 11 Enterprise Available memory (MB): 65225 Available CPU cores: 32 Binaries: Node: 20.11.1 npm: 10.2.4 Yarn: 1.22.19 pnpm: N/A Relevant Packages: next: 15.0.4-canary.6 // Latest available version is detected (15.0.4-canary.6). eslint-config-next: N/A react: 18.3.1 react-dom: 18.3.1 typescript: 5.4.5 Next.js Config: output: export
Which example does this report relate to?
No response
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
Trying to get the Monaco editor to work with Turbopack.
Expected Behavior
I don't know if it's trying to import an empty string or what it is doing but it is failing when I do a dynamic import for the monaco editor api module. Like so,
It's probably failing because it cannot resolve this statically but it's not supposed to either, I don't know how debug, troubleshoot or investigate this myself further. All I want Turbopack to do is to leave this dynamic import alone. Furthermore, this is a library so I cannot modify the call site. I just want Turbopack to not complain about this, I know what I'm doing.
To Reproduce
Adapt this sample from Monaco for Turbopack
https://github.com/microsoft/monaco-editor/tree/main/samples/browser-esm-webpack-small
The text was updated successfully, but these errors were encountered: