Closed Ehesp closed 3 years ago
Can you post the smallest content that produces this error?
The sample plugin also isn't doing anything?
Ok sorry was being a bit of an idiot.
- import shiki from 'shiki';
+ import { getHighlighter } from 'shiki';
This fixed it, so nothing to do with your library sorry. The only thing I did to find the error was log it here, which returned TypeError: Cannot read property 'getHighlighter' of undefined
.
It seems that error has no location
property, hence the original error.
Might still be something to change here, to throw the actual error instead of hiding it and throwing something else? 🤔 if it's something here, though?
@Ehesp hey! were you successful in getting the shiki working with xdm? I'm trying out the same but unable to 😅
If errors are still swallowed, I would appreciate a reproduction so it can be fixed
Hey! Here's a reproduction:
Everything works alright until I try to use this https://github.com/stefanprobst/remark-shiki in order to build the HTML during build time (I'd prefer not to to have this be done on the client side at runtime)
I tried to use the given instruction as best I could, sorry if I missed anything!
Repo: https://github.com/sreetamdas/example-next-mdx-bundler-shiki CodeSandbox: https://codesandbox.io/s/github/sreetamdas/example-next-mdx-bundler-shiki?file=/package.json Live: https://qnr6j.sse.codesandbox.io/color
> _mdx_bundler_entry_point-6d299e15-739d-4fea-9414-5e47c4d4f456.mdx:0:0: error: [plugin: esbuild-xdm]
0 │ ---
╵ ^
Error: Build failed with 1 error:
_mdx_bundler_entry_point-6d299e15-739d-4fea-9414-5e47c4d4f456.mdx:0:0: error: [plugin: esbuild-xdm]
at failureErrorWithLog (/Users/sreetamdas/dev/projects/example-next-mdx-bundler-shiki/node_modules/esbuild/lib/main.js:1475:15)
at /Users/sreetamdas/dev/projects/example-next-mdx-bundler-shiki/node_modules/esbuild/lib/main.js:1133:28
at runOnEndCallbacks (/Users/sreetamdas/dev/projects/example-next-mdx-bundler-shiki/node_modules/esbuild/lib/main.js:923:63)
at buildResponseToResult (/Users/sreetamdas/dev/projects/example-next-mdx-bundler-shiki/node_modules/esbuild/lib/main.js:1131:7)
at /Users/sreetamdas/dev/projects/example-next-mdx-bundler-shiki/node_modules/esbuild/lib/main.js:1240:14
at /Users/sreetamdas/dev/projects/example-next-mdx-bundler-shiki/node_modules/esbuild/lib/main.js:611:9
at handleIncomingPacket (/Users/sreetamdas/dev/projects/example-next-mdx-bundler-shiki/node_modules/esbuild/lib/main.js:708:9)
at Socket.readFromStdout (/Users/sreetamdas/dev/projects/example-next-mdx-bundler-shiki/node_modules/esbuild/lib/main.js:578:7)
at Socket.emit (node:events:394:28)
at addChunk (node:internal/streams/readable:312:12) {
errors: [
{
detail: [Error],
location: [Object],
notes: [],
pluginName: 'esbuild-xdm',
text: ''
}
],
warnings: []
}
Thanks for the repro. This is, sort of, with @stefanprobst/remark-shiki
. The swallowed error is:
Error: Cannot handle unknown node `raw`
at Object.unknown (file:///Users/tilde/Projects/oss/example-next-mdx-bundler-shiki/node_modules/hast-util-to-estree/index.js:155:9)
// ...
@stefanprobst/remark-shiki
is injecting HTML into the AST. xdm (and the upcoming MDX v2) don’t handle HTML.
You could get around it, by using rehype-raw
with these options, in rehypePlugins
.
Having to use rehype-raw
is documented in the readme of @stefanprobst/remark-shiki
.
Note that there are several rehype shiki plugins! rehype-shiki
, seems to build an AST, not strings of HTML. Maybe the other ones work better.
Meanwhile I’ll try and make sure errors aren’t swallowed
/cc @stefanprobst, author of @stefanprobst/remark-shiki
hi, yep the example in the docs shows using rehype-raw
.
as @wooorm mentioned, there are a couple of rehype shiki plugins - i've got my own one as well, which i'm successfully using with xdm.
Thanks for the help @wooorm @stefanprobst! I ended up mixing remark-shiki and remark-mdx-code-meta since I wasn't able to make them work on their own together (PR) — I should have read the docs better haha
Thanks again!
Initial checklist
Steps to reproduce
I'm trying to use
shiki
with a remark plugin usingremark-shiki
.Whenever I include the plugin, I hit the following error:
I wasn't sure this was an issue with the plugin or not, so I confirmed the same error occurs with a basic plugin: