Imports/exports in function-body #2157
-
I'm working on a Next.js project that uses MDX2. I'm working on refactoring it from using local mdx files/webpack to using MDX On Demand or Hashicorp's next-mdx-remote. My project is highly dependent on imports/exports because I utilize remark/rehype plugins to create variables and export a default Layout. I tried using baseUrl but I got the following error:
Here's my source code/attempt |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Ways I've attempted to solve this problem:
Ideas I have to solve this problem:
|
Beta Was this translation helpful? Give feedback.
-
Ooo I did some more searching and found this - I shall try this out..,. |
Beta Was this translation helpful? Give feedback.
-
If you are going to run MDX code on the client in a browser, without a bundler, then you get actual imports. The browser will fetch those files. Your server will need to send those files back. Sort of how it used to be 10 years ago: you had different JS files on a server, and you had The URL must also reflect that. An actual URL to a file on a website where the code runs from. You can also run code inside Node.js. Then the files can exist on that server locally too. And they can be imported. Node.js can access That’s why However, if all your things are TypeScript, and you’re using tools to bundle all of that, that interferes. The browser doesn’t understand TypeScript.
This should work. Perhaps you weren’t passing the provider correctly? Note that exports (except |
Beta Was this translation helpful? Give feedback.
If you are going to run MDX code on the client in a browser, without a bundler, then you get actual imports. The browser will fetch those files. Your server will need to send those files back.
Sort of how it used to be 10 years ago: you had different JS files on a server, and you had
script
tags in an HTML page. The browser then got those files from the server for you.The URL must also reflect that. An actual URL to a file on a website where the code runs from.
You can also run code inside Node.js. Then the files can exist on that server locally too. And they can be imported. Node.js can access
file://...
. But browsers can’t.That’s why
options.useDynamicImport
andoptions.baseURL
exist.…