code-hike / codehike

Build rich content websites with Markdown and React
https://codehike.org
MIT License
4.8k stars 150 forks source link

Cannot read properties of undefined (reading 'id') #122

Closed willin closed 2 years ago

willin commented 2 years ago
error running remarkCodeHike TypeError: Cannot read properties of undefined (reading 'id')
    at Resolver.addLanguage (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/node_modules/shiki/dist/index.js:1771:28)
    at Object.loadLanguage (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/node_modules/shiki/dist/index.js:2130:19)
    at Object.<anonymous> (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:110:54)
    at step (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:65:23)
    at Object.next (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:46:53)
    at /Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:39:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:35:12)
    at Object.highlight (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:77:12)
    at /Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/mdx/dist/index.cjs.js:809:54
✘ [ERROR] [plugin esbuild-xdm] TypeError: Cannot read properties of undefined (reading 'id')
    at Resolver.addLanguage (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/node_modules/shiki/dist/index.js:1771:28)
    at Object.loadLanguage (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/node_modules/shiki/dist/index.js:2130:19)
    at Object.<anonymous> (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:110:54)
    at step (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:65:23)
    at Object.next (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:46:53)
    at /Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:39:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:35:12)
    at Object.highlight (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:77:12)
    at /Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/mdx/dist/index.cjs.js:809:54

    _mdx_bundler_entry_point-b319b6aa-e3d3-4eed-acb4-fd358c2231e5.mdx:0:0:
      0 │ ---
        ╵ ^

Error: Build failed with 1 error:
_mdx_bundler_entry_point-b319b6aa-e3d3-4eed-acb4-fd358c2231e5.mdx:0:0: ERROR: [plugin: esbuild-xdm] TypeError: Cannot read properties of undefined (reading 'id')
    at Resolver.addLanguage (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/node_modules/shiki/dist/index.js:1771:28)
    at Object.loadLanguage (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/node_modules/shiki/dist/index.js:2130:19)
    at Object.<anonymous> (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:110:54)
    at step (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:65:23)
    at Object.next (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:46:53)
    at /Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:39:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:35:12)
    at Object.highlight (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:77:12)
    at /Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/mdx/dist/index.cjs.js:809:54
    at failureErrorWithLog (/Users/v0/Sites/willin.wang/scripts/node_modules/esbuild/lib/main.js:1557:15)
    at /Users/v0/Sites/willin.wang/scripts/node_modules/esbuild/lib/main.js:1215:28
    at runOnEndCallbacks (/Users/v0/Sites/willin.wang/scripts/node_modules/esbuild/lib/main.js:1005:63)
    at buildResponseToResult (/Users/v0/Sites/willin.wang/scripts/node_modules/esbuild/lib/main.js:1213:7)
    at /Users/v0/Sites/willin.wang/scripts/node_modules/esbuild/lib/main.js:1322:14
    at /Users/v0/Sites/willin.wang/scripts/node_modules/esbuild/lib/main.js:637:9
    at handleIncomingPacket (/Users/v0/Sites/willin.wang/scripts/node_modules/esbuild/lib/main.js:734:9)
    at Socket.readFromStdout (/Users/v0/Sites/willin.wang/scripts/node_modules/esbuild/lib/main.js:604:7)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12) {
  errors: [
    {
      detail: TypeError: Cannot read properties of undefined (reading 'id')
          at Resolver.addLanguage (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/node_modules/shiki/dist/index.js:1771:28)
          at Object.loadLanguage (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/node_modules/shiki/dist/index.js:2130:19)
          at Object.<anonymous> (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:110:54)
          at step (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:65:23)
          at Object.next (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:46:53)
          at /Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:39:71
          at new Promise (<anonymous>)
          at __awaiter (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:35:12)
          at Object.highlight (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:77:12)
          at /Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/mdx/dist/index.cjs.js:809:54,
      location: [Object],
      notes: [],
      pluginName: 'esbuild-xdm',
      text: "TypeError: Cannot read properties of undefined (reading 'id')\n" +
        '    at Resolver.addLanguage (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/node_modules/shiki/dist/index.js:1771:28)\n' +
        '    at Object.loadLanguage (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/node_modules/shiki/dist/index.js:2130:19)\n' +
        '    at Object.<anonymous> (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:110:54)\n' +
        '    at step (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:65:23)\n' +
        '    at Object.next (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:46:53)\n' +
        '    at /Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:39:71\n' +
        '    at new Promise (<anonymous>)\n' +
        '    at __awaiter (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:35:12)\n' +
        '    at Object.highlight (/Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/highlighter/dist/index.cjs.js:77:12)\n' +
        '    at /Users/v0/Sites/willin.wang/scripts/node_modules/@code-hike/mdx/dist/index.cjs.js:809:54'
    }
  ],
  warnings: []
}
Errored.

here's my compile codes: https://github.com/willin/willin.wang/blob/main/scripts/mdx.js

i just added the plugin:

// some like this:

const { remarkCodeHike } = require('@code-hike/mdx');
const theme = require('shiki/themes/nord.json');

  const { frontmatter, code } = await bundleMDX({
    source: fileContent,
    ...(Object.keys(files).length > 0 ? { files } : {}),
    xdmOptions(options) {
      // eslint-disable-next-line no-param-reassign
      options.remarkPlugins = [
        ...(options.remarkPlugins ?? []),
        [remarkCodeHike, { theme }],
        remarkMdxImages
      ];

      return options;
    }

  });

the first post compiled successfully:

<pre class=\"ch-code\" style=\"margin:0;overflow:hidden;opacity:0\"><code class=\"ch-code-scroll-parent\"><br/><div><div style=\"display:inline-block\"><span>git clone https://github.com/discourse/discourse_docker.git /var/discourse</span></div></div><div><div style=\"display:inline-block\"><span>cd /var/discourse</span></div></div><br/></code></pre>

however when second, errored.

pomber commented 2 years ago

Thanks for reporting the error, could you also post the .mdx file?

willin commented 2 years ago

i found the reason.

there's a mermaid code in my mdx

\```mermaid
graph LR
    Start1(Start)
    --Bot 启动--> check1[检查群内的非 Authing 用户]
    --> addUser[添加 Authing 用户并消息提醒绑定手机号]
    --> End1(End)
\```
pomber commented 2 years ago

OK, there's no syntax highlighting for mermaid, but Code Hike shouldn't crash (#117).

github-actions[bot] commented 2 years ago

:rocket: Issue was released in v0.3.0 :rocket: