kentcdodds / mdx-bundler

🦤 Give me MDX/TSX strings and I'll give you back a component you can render. Supports imports!
MIT License
1.77k stars 75 forks source link

mdx-bundler needs to have its dependencies updated #24

Closed benwis closed 3 years ago

benwis commented 3 years ago

Relevant code or config

What you did:

What happened:

Reproduction repository:

Problem description: I updated from a pre xdm version of mdx-bundler to the current bundler on Remix v0.15 with the old compiler, and it appears mdx-bundler will not compile any content. I tried substituting my post content with the demo in the readme content was unsuccessful.

This might be the relevant error:

<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><title>Oops!</title></head><body><div><h1>App Error</h1><pre>Named export &#x27;generate&#x27; not found. The requested module &#x27;astring&#x27; is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from &#x27;astring&#x27;;
const {baseGenerator, generate} = pkg;
</pre><p>Replace this UI with what you want users to see when your app throws uncaught errors. The file is at <code>app/App.tsx</code>.</p></div><link rel="modulepreload" href="/build/_shared/react-dom-af783853.js"/><link rel="modulepreload" href="/build/_shared/__remix-run/react-57beb414.js"/><link rel="modulepreload" href="/build/_shared/react-f725fe97.js"/><link rel="modulepreload" href="/build/_shared/object-assign-510802f4.js"/><link rel="modulepreload" href="/build/_shared/scheduler-a04990bf.js"/><link rel="modulepreload" href="/build/_shared/history-f36bd753.js"/><link rel="modulepreload" href="/build/_shared/__babel/runtime-ed0db730.js"/><link rel="modulepreload" href="/build/_shared/react-router-125d454f.js"/><link rel="modulepreload" href="/build/_shared/prop-types-0a27d4c1.js"/><link rel="modulepreload" href="/build/_shared/react-is-9bd4a37b.js"/><link rel="modulepreload" href="/build/root-6c3b2226.js"/><link rel="modulepreload" href="/build/_shared/react-router-dom-5cafc605.js"/><link rel="modulepreload" href="/build/_shared/react-moment-69e65e4f.js"/><link rel="modulepreload" href="/build/_shared/index-b6dcd8ad.js"/><link rel="modulepreload" href="/build/_shared/graphql-request-13a5e6fe.js"/><link rel="modulepreload" href="/build/_shared/moment-063fa120.js"/><link rel="modulepreload" href="/build/_shared/index-9e7d4c1b.js"/><link rel="modulepreload" href="/build/_shared/cross-fetch-c6e83489.js"/><link rel="modulepreload" href="/build/_shared/graphql-ee6475a1.js"/><link rel="modulepreload" href="/build/_shared/extract-files-eda57c75.js"/><link rel="modulepreload" href="/build/_shared/form-data-35f14aa2.js"/><link rel="modulepreload" href="/build/routes/blog-fdcdb93d.js"/><link rel="modulepreload" href="/build/_shared/mdx-bundler-3054ae34.js"/><link rel="modulepreload" href="/build/path"/><link rel="modulepreload" href="/build/_shared/remark-frontmatter-a96f9e83.js"/><link rel="modulepreload" href="/build/_shared/micromark-extension-frontmatter-ead1a148.js"/><link rel="modulepreload" href="/build/_shared/fault-87b06a15.js"/><link rel="modulepreload" href="/build/_shared/format-ef0c8e7d.js"/><link rel="modulepreload" href="/build/_shared/mdast-util-frontmatter-1eb3e236.js"/><link rel="modulepreload" href="/build/_shared/remark-mdx-frontmatter-079ecf60.js"/><link rel="modulepreload" href="/build/_shared/estree-util-is-identifier-name-dbef2cfd.js"/><link rel="modulepreload" href="/build/_shared/estree-util-value-to-estree-46f2306a.js"/><link rel="modulepreload" href="/build/_shared/is-plain-obj-3e03ed06.js"/><link rel="modulepreload" href="/build/_shared/js-yaml-4fed501f.js"/><link rel="modulepreload" href="/build/_shared/toml-6eb0502e.js"/><link rel="modulepreload" href="/build/_shared/unist-util-visit-3423fa69.js"/><link rel="modulepreload" href="/build/_shared/unist-util-visit-parents-33bca2c9.js"/><link rel="modulepreload" href="/build/_shared/unist-util-is-b8a0263c.js"/><link rel="modulepreload" href="/build/_shared/gray-matter-dc1196f5.js"/><link rel="modulepreload" href="/build/fs"/><link rel="modulepreload" href="/build/_shared/section-matter-0d15c47c.js"/><link rel="modulepreload" href="/build/_shared/kind-of-7b83e3ef.js"/><link rel="modulepreload" href="/build/_shared/extend-shallow-3f03756a.js"/><link rel="modulepreload" href="/build/_shared/is-extendable-e9a66a9d.js"/><link rel="modulepreload" href="/build/_shared/strip-bom-string-2d7a6d5a.js"/><link rel="modulepreload" href="/build/_shared/esbuild-9cebdd44.js"/><link rel="modulepreload" href="/build/child_process"/><link rel="modulepreload" href="/build/crypto"/><link rel="modulepreload" href="/build/os"/><link rel="modulepreload" href="/build/tty"/><link rel="modulepreload" href="/build/worker_threads"/><link rel="modulepreload" href="/build/_shared/__esbuild-plugins/node-resolve-fbf78b19.js"/><link rel="modulepreload" href="/build/_shared/builtin-modules-abc042ab.js"/><link rel="modulepreload" href="/build/module"/><link rel="modulepreload" href="/build/_shared/resolve-c0760374.js"/><link rel="modulepreload" href="/build/_shared/path-parse-a9f1b4e5.js"/><link rel="modulepreload" href="/build/_shared/is-core-module-ff091d4a.js"/><link rel="modulepreload" href="/build/_shared/has-59288659.js"/><link rel="modulepreload" href="/build/_shared/function-bind-6908fa26.js"/><link rel="modulepreload" href="/build/util"/><link rel="modulepreload" href="/build/_shared/__fal-works/esbuild-plugin-global-externals-73787170.js"/><link rel="modulepreload" href="/build/routes/blog/$post-80ac699f.js"/><script>window.__remixContext = {'matches':[{'params':{},'pathname':'/','route':{'path':'/','id':'root','module':'/build/root-6c3b2226.js','hasLoader':true}},{'params':{},'pathname':'/blog','route':{'path':'blog','caseSensitive':false,'id':'routes/blog','parentId':'root','module':'/build/routes/blog-fdcdb93d.js','imports':['/build/_shared/react-router-dom-5cafc605.js','/build/_shared/react-moment-69e65e4f.js','/build/_shared/index-b6dcd8ad.js','/build/_shared/graphql-request-13a5e6fe.js','/build/_shared/moment-063fa120.js','/build/_shared/index-9e7d4c1b.js','/build/_shared/cross-fetch-c6e83489.js','/build/_shared/graphql-ee6475a1.js','/build/_shared/extract-files-eda57c75.js','/build/_shared/form-data-35f14aa2.js'],'hasLoader':true}},{'params':{'post':'compile-mdx-on-remix'},'pathname':'/blog/compile-mdx-on-remix','route':{'path':':post','caseSensitive':false,'id':'routes/blog/$post','parentId':'routes/blog','module':'/build/routes/blog/$post-80ac699f.js','imports':['/build/_shared/mdx-bundler-3054ae34.js','/build/path','/build/_shared/remark-frontmatter-a96f9e83.js','/build/_shared/micromark-extension-frontmatter-ead1a148.js','/build/_shared/fault-87b06a15.js','/build/_shared/format-ef0c8e7d.js','/build/_shared/mdast-util-frontmatter-1eb3e236.js','/build/_shared/remark-mdx-frontmatter-079ecf60.js','/build/_shared/estree-util-is-identifier-name-dbef2cfd.js','/build/_shared/estree-util-value-to-estree-46f2306a.js','/build/_shared/is-plain-obj-3e03ed06.js','/build/_shared/js-yaml-4fed501f.js','/build/_shared/toml-6eb0502e.js','/build/_shared/unist-util-visit-3423fa69.js','/build/_shared/unist-util-visit-parents-33bca2c9.js','/build/_shared/unist-util-is-b8a0263c.js','/build/_shared/gray-matter-dc1196f5.js','/build/fs','/build/_shared/section-matter-0d15c47c.js','/build/_shared/kind-of-7b83e3ef.js','/build/_shared/extend-shallow-3f03756a.js','/build/_shared/is-extendable-e9a66a9d.js','/build/_shared/strip-bom-string-2d7a6d5a.js','/build/_shared/esbuild-9cebdd44.js','/build/child_process','/build/crypto','/build/os','/build/tty','/build/worker_threads','/build/_shared/__esbuild-plugins/node-resolve-fbf78b19.js','/build/_shared/builtin-modules-abc042ab.js','/build/module','/build/_shared/resolve-c0760374.js','/build/_shared/path-parse-a9f1b4e5.js','/build/_shared/is-core-module-ff091d4a.js','/build/_shared/has-59288659.js','/build/_shared/function-bind-6908fa26.js','/build/util','/build/_shared/__fal-works/esbuild-plugin-global-externals-73787170.js'],'hasLoader':true}}],'componentDidCatchEmulator':{'trackBoundaries':true,'renderBoundaryRouteId':null,'loaderBoundaryRouteId':'root','error':{'message':'Named export \'generate\' not found. The requested module \'astring\' is a CommonJS module, which may not support all module.exports as named exports.\nCommonJS modules can always be imported via the default export, for example using:\n\nimport pkg from \'astring\';\nconst {baseGenerator, generate} = pkg;\n','stack':'file:///celPool/celData/Works/projects/vidette-remix-express/node_modules/xdm/lib/plugin/recma-stringify.js:2\nimport {baseGenerator, generate} from \'astring\'\n                       ^^^^^^^^\nSyntaxError: Named export \'generate\' not found. The requested module \'astring\' is a CommonJS module, which may not support all module.exports as named exports.\nCommonJS modules can always be imported via the default export, for example using:\n\nimport pkg from \'astring\';\nconst {baseGenerator, generate} = pkg;\n\n    at ModuleJob._instantiate (file://node:internal/modules/esm/module_job:105:21)\n    at async ModuleJob.run (file://node:internal/modules/esm/module_job:151:5)\n    at async Loader.import (file://node:internal/modules/esm/loader:166:24)\n    at async importModuleDynamicallyWrapper (file://node:internal/vm/module:435:15)\n    at async Object.bundleMDX (file:///celPool/celData/Works/projects/vidette-remix-express/node_modules/mdx-bundler/dist/index.js:53:27)\n    at async Object.loader (file:///celPool/celData/Works/projects/vidette-remix-express/build/routes/blog/$post.js:28582:16)\n    at async Object.loadRouteData (file:///celPool/celData/Works/projects/vidette-remix-express/node_modules/@remix-run/node/data.js:16:16)\n    at async Promise.all (file://index 2)\n    at async handleDocumentRequest (file:///celPool/celData/Works/projects/vidette-remix-express/node_modules/@remix-run/node/server.js:114:28)\n    at async /celPool/celData/Works/projects/vidette-remix-express/node_modules/@remix-run/express/server.js:32:22'}},'routeData':{'root':{'date':'2021-04-14T18:07:32.974Z','env':'development'},'routes/blog':{'data':{'posts':[{'title':'Compile MDX on Remix','id':2,'author_id':'646b5408-538f-4de9-aa1b-d08b17edcec5','author_name':'benwis','feat_img':'https://celcyon-aws.imgix.net/mdx.png','feat_img_alt':'MDX logo','created_at':'2021-02-15T18:50:03.894408+00:00','excerpt':'MDX is perfect for writing content, but getting it to work on Remix can be difficult.','slug':'compile-mdx-on-remix'},{'title':'Add Fathom Analytics to Remix','id':3,'author_id':'646b5408-538f-4de9-aa1b-d08b17edcec5','author_name':'benwis','feat_img':'https://celcyon-aws.imgix.net/fathom.jpg','feat_img_alt':'Fathom Analytics logo','created_at':'2021-02-01T18:53:07.561874+00:00','excerpt':'Learn how to track user activity while respecting their privacy.','slug':'add-fathom-to-remix'},{'title':'Remix-Run and GraphQL','id':4,'author_id':'646b5408-538f-4de9-aa1b-d08b17edcec5','author_name':'benwis','feat_img':'https://celcyon-aws.imgix.net/graphql-blue.jpg','feat_img_alt':'GraphQL logo on purple background','created_at':'2021-01-23T18:53:30.048452+00:00','excerpt':'GraphQL and Remix integrate beautifully, whether in actions, loaders, or components!','slug':'Remix-Run-and-GraphQL'}]}},'routes/blog/$post':null}};</script><script type="module">import * as route0 from "/build/root-6c3b2226.js";
import * as route1 from "/build/routes/blog-fdcdb93d.js";
import * as route2 from "/build/routes/blog/$post-80ac699f.js";
    window.__remixRouteModules = {"root":route0,"routes/blog":route1,"routes/blog/$post":route2};</script><script src="/build/manifest-10fbfaad.js" type="module"></script><script src="/build/entry.client-3c5e76b8.js" type="module"></script></body></html>

Suggested solution:

kentcdodds commented 3 years ago

I'm sorry, but this doesn't give us enough information to be able to help much 😬

A reproduction would be good.

benwis commented 3 years ago

I know, I'm trying to dig into it now. bundleMDX() just returns undefined , the remix console just says there was an error running the loader, and the console output in the browser shows this

GET http://127.0.0.1:3000/blog/compile-mdx-on-remix 500 (Internal Server Error)
compile-mdx-on-remix:6 GET http://127.0.0.1:3000/build/path net::ERR_ABORTED 404 (Not Found)
compile-mdx-on-remix:6 GET http://127.0.0.1:3000/build/fs net::ERR_ABORTED 404 (Not Found)
compile-mdx-on-remix:6 GET http://127.0.0.1:3000/build/worker_threads net::ERR_ABORTED 404 (Not Found)
compile-mdx-on-remix:6 GET http://127.0.0.1:3000/build/child_process net::ERR_ABORTED 404 (Not Found)
compile-mdx-on-remix:6 GET http://127.0.0.1:3000/build/crypto net::ERR_ABORTED 404 (Not Found)
compile-mdx-on-remix:6 GET http://127.0.0.1:3000/build/tty net::ERR_ABORTED 404 (Not Found)
compile-mdx-on-remix:6 GET http://127.0.0.1:3000/build/os net::ERR_ABORTED 404 (Not Found)
compile-mdx-on-remix:6 GET http://127.0.0.1:3000/build/module net::ERR_ABORTED 404 (Not Found)
compile-mdx-on-remix:6 GET http://127.0.0.1:3000/build/util net::ERR_ABORTED 404 (Not Found)
compile-mdx-on-remix:1 Uncaught TypeError: Failed to resolve module specifier "path". Relative references must start with either "/", "./", or "../".
react-dom-af783853.js:9 TypeError: Cannot read property 'root' of undefined
    at react-57beb414.js:1
    at Array.map (<anonymous>)
    at b (react-57beb414.js:1)
    at react-57beb414.js:1
    at Object.useMemo (react-dom-af783853.js:9)
    at Object.t.useMemo (react-f725fe97.js:9)
    at M (react-57beb414.js:1)
    at no (react-dom-af783853.js:9)
    at Qu (react-dom-af783853.js:9)
    at Ci (react-dom-af783853.js:9)
au @ react-dom-af783853.js:9
t.callback @ react-dom-af783853.js:9
sa @ react-dom-af783853.js:9
du @ react-dom-af783853.js:9
Pi @ react-dom-af783853.js:9
e.unstable_runWithPriority @ scheduler-a04990bf.js:9
Bl @ react-dom-af783853.js:9
Ni @ react-dom-af783853.js:9
hi @ react-dom-af783853.js:9
si @ react-dom-af783853.js:9
Yi @ react-dom-af783853.js:9
(anonymous) @ react-dom-af783853.js:9
gi @ react-dom-af783853.js:9
ns @ react-dom-af783853.js:9
hydrate @ react-dom-af783853.js:9
(anonymous) @ entry.client-3c5e76b8.js:1
react-57beb414.js:1 Uncaught TypeError: Cannot read property 'root' of undefined
    at react-57beb414.js:1
    at Array.map (<anonymous>)
    at b (react-57beb414.js:1)
    at react-57beb414.js:1
    at Object.useMemo (react-dom-af783853.js:9)
    at Object.t.useMemo (react-f725fe97.js:9)
    at M (react-57beb414.js:1)
    at no (react-dom-af783853.js:9)
    at Qu (react-dom-af783853.js:9)
    at Ci (react-dom-af783853.js:9)
(anonymous) @ react-57beb414.js:1
b @ react-57beb414.js:1
(anonymous) @ react-57beb414.js:1
useMemo @ react-dom-af783853.js:9
t.useMemo @ react-f725fe97.js:9
M @ react-57beb414.js:1
no @ react-dom-af783853.js:9
Qu @ react-dom-af783853.js:9
Ci @ react-dom-af783853.js:9
Ei @ react-dom-af783853.js:9
Si @ react-dom-af783853.js:9
hi @ react-dom-af783853.js:9
si @ react-dom-af783853.js:9
Yi @ react-dom-af783853.js:9
(anonymous) @ react-dom-af783853.js:9
gi @ react-dom-af783853.js:9
ns @ react-dom-af783853.js:9
hydrate @ react-dom-af783853.js:9
(anonymous) @ entry.client-3c5e76b8.js:1
contentscript.js:390 Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.
    at startMutationObserver (contentscript.js:390)
    at Object.start (contentscript.js:450)

Let me try to stand up a repo, I shjould be able to do that in 20 minutes or so.

benwis commented 3 years ago

Reproducing Repo. Doing the exact same thing as my main site! https://github.com/benwis/kent-remix-mdx_bundler-broken

benwis commented 3 years ago

Looks like with either the new compiler(and the errorneous imports removed) or the old compiler, the error now boils down to this:

App Error
Named export 'generate' not found. The requested module 'astring' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'astring';
const {baseGenerator, generate} = pkg;
Replace this UI with what you want users to see when your app throws uncaught errors. The file is at app/App.tsx.
benwis commented 3 years ago

All this work, and it turns out the only thing wrong is that mdx-bundler has some old deps. If you run yarn upgrade or your equivalent to update the package.jsons, you're all good. Thanks for maintaining this!

Arcath commented 3 years ago

I've updated to the latest everything in #26 so this can be closed when that gets merged.

willin commented 2 years ago
index.tsx:1295 Uncaught TypeError: Cannot read properties of undefined (reading 'pathname')
    at resolveTo (index.tsx:1295:39)
    at index.tsx:620:11
    at mountMemo (react-dom.development.js:15846:19)
    at Object.useMemo (react-dom.development.js:16219:16)
    at useMemo (react.development.js:1532:21)
    at useResolvedPath (index.tsx:619:10)
    at useHref (index.tsx:361:36)
    at components.js:343:14
    at renderWithHooks (react-dom.development.js:14985:18)
    at updateForwardRef (react-dom.development.js:17044:20)
resolveTo @ index.tsx:1295
(匿名) @ index.tsx:620
mountMemo @ react-dom.development.js:15846
useMemo @ react-dom.development.js:16219
useMemo @ react.development.js:1532
useResolvedPath @ index.tsx:619
useHref @ index.tsx:361
(匿名) @ components.js:343
renderWithHooks @ react-dom.development.js:14985
updateForwardRef @ react-dom.development.js:17044
beginWork @ react-dom.development.js:19098
callCallback2 @ react-dom.development.js:3945
invokeGuardedCallbackDev @ react-dom.development.js:3994
invokeGuardedCallback @ react-dom.development.js:4056
beginWork$1 @ react-dom.development.js:23964
performUnitOfWork @ react-dom.development.js:22776
workLoopSync @ react-dom.development.js:22707
renderRootSync @ react-dom.development.js:22670
performSyncWorkOnRoot @ react-dom.development.js:22293
scheduleUpdateOnFiber @ react-dom.development.js:21881
updateContainer @ react-dom.development.js:25482
(匿名) @ react-dom.development.js:26021
unbatchedUpdates @ react-dom.development.js:22431
legacyRenderSubtreeIntoContainer @ react-dom.development.js:26020
hydrate @ react-dom.development.js:26086
(匿名) @ entry.client.tsx:4

mdx with image in