Skip to content
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

esbuild errors result in "Cannot read property 'line' of undefined" error #75

Closed
4 tasks done
kentcdodds opened this issue Aug 11, 2021 · 2 comments
Closed
4 tasks done

Comments

@kentcdodds
Copy link


Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)

Affected packages and versions: 1.12.2

Steps to reproduce

Still working on figuring out how to reproduce this reliably (for a separate issue I'm working on actually).

Expected behavior

Useful error messages when compiling fails.

Actual behavior

When there's an error in compiling MDX, xdm tries to construct a helpful error message, but ends up erroring out in the process resulting in a very unhelpful error message. Here's what it looks like:

> ../node_modules/esbuild/lib/main.js:869:27: error: [plugin: esbuild-xdm] Cannot read property 'line' of undefined
   869 │               let result = await callback2({
       ╵                            ^
   at onload (file:///Users/kentcdodds/code/remix-kentcdodds/node_modules/xdm/lib/integration/esbuild.js:172:17)
   at processTicksAndRejections (node:internal/process/task_queues:96:5)
   at callback (/Users/kentcdodds/code/remix-kentcdodds/node_modules/esbuild/lib/main.js:869:28)
   at handleRequest (/Users/kentcdodds/code/remix-kentcdodds/node_modules/esbuild/lib/main.js:652:30)
  ../node_modules/esbuild/lib/main.js:736:22: note: This error came from the "onLoad" callback registered here
   736 │         let promise = setup({
       ╵                       ^
   at setup (file:///Users/kentcdodds/code/remix-kentcdodds/node_modules/xdm/lib/integration/esbuild.js:69:11)
   at handlePlugins (/Users/kentcdodds/code/remix-kentcdodds/node_modules/esbuild/lib/main.js:736:23)
   at Object.buildOrServe (/Users/kentcdodds/code/remix-kentcdodds/node_modules/esbuild/lib/main.js:1024:7)
   at /Users/kentcdodds/code/remix-kentcdodds/node_modules/esbuild/lib/main.js:1754:17
   at new Promise (<anonymous>)
   at Object.build (/Users/kentcdodds/code/remix-kentcdodds/node_modules/esbuild/lib/main.js:1753:14)
   at Object.build (/Users/kentcdodds/code/remix-kentcdodds/node_modules/esbuild/lib/main.js:1629:51)
   at bundleMDX (/Users/kentcdodds/code/remix-kentcdodds/node_modules/mdx-bundler/dist/index.js:202:33)
   at processTicksAndRejections (node:internal/process/task_queues:96:5)
   at compileMdx (/Users/kentcdodds/code/remix-kentcdodds/build/index.js:664:18)
   at getFreshValue (/Users/kentcdodds/code/remix-kentcdodds/build/index.js:1234:17)
   at cachified (/Users/kentcdodds/code/remix-kentcdodds/build/index.js:1137:15)
   at getFreshValue (/Users/kentcdodds/code/remix-kentcdodds/build/index.js:1165:10)
   at cachified (/Users/kentcdodds/code/remix-kentcdodds/build/index.js:1137:15)
   at Object.loader18 (/Users/kentcdodds/code/remix-kentcdodds/build/index.js:8457:22)

This is going through mdx-bundler. The line that's erroring out is this one:

start.line != null &&

If I add console.error(error) right here, I get this output:

TypeError: Cannot read property '11' of undefined
    at lineStart (file:///Users/kentcdodds/code/remix-kentcdodds/node_modules/micromark-extension-gfm-table/lib/syntax.js:563:30)
    at go (/Users/kentcdodds/code/remix-kentcdodds/node_modules/micromark/dist/util/create-tokenizer.js:136:13)
    at main (/Users/kentcdodds/code/remix-kentcdodds/node_modules/micromark/dist/util/create-tokenizer.js:127:11)
    at Object.write (/Users/kentcdodds/code/remix-kentcdodds/node_modules/micromark/dist/util/create-tokenizer.js:70:5)
    at continueFlow (/Users/kentcdodds/code/remix-kentcdodds/node_modules/micromark/dist/initialize/document.js:119:15)
    at flowContinue (/Users/kentcdodds/code/remix-kentcdodds/node_modules/micromark/dist/initialize/document.js:97:7)
    at go (/Users/kentcdodds/code/remix-kentcdodds/node_modules/micromark/dist/util/create-tokenizer.js:136:13)
    at main (/Users/kentcdodds/code/remix-kentcdodds/node_modules/micromark/dist/util/create-tokenizer.js:130:9)
    at Object.write (/Users/kentcdodds/code/remix-kentcdodds/node_modules/micromark/dist/util/create-tokenizer.js:70:5)
    at fromMarkdown (/Users/kentcdodds/code/remix-kentcdodds/node_modules/xdm/node_modules/mdast-util-from-markdown/dist/index.js:26:34)
    at parse (/Users/kentcdodds/code/remix-kentcdodds/node_modules/xdm/node_modules/remark-parse/index.js:13:12)
    at Function.parse (/Users/kentcdodds/code/remix-kentcdodds/node_modules/xdm/node_modules/unified/index.js:271:12)
    at pipelineParse (/Users/kentcdodds/code/remix-kentcdodds/node_modules/xdm/node_modules/unified/index.js:23:16)
    at wrapped (/Users/kentcdodds/code/remix-kentcdodds/node_modules/xdm/node_modules/trough/wrap.js:25:19)
    at next (/Users/kentcdodds/code/remix-kentcdodds/node_modules/xdm/node_modules/trough/index.js:57:24)
    at Object.run (/Users/kentcdodds/code/remix-kentcdodds/node_modules/xdm/node_modules/trough/index.js:31:10) {
  fatal: true
}

I wouldn't call that very helpful, but it directs me at least to the source of the error much better 😅

I think the solution is to simply handle errors that lack location information better.

@kentcdodds kentcdodds mentioned this issue Aug 11, 2021
4 tasks
@wooorm
Copy link
Owner

wooorm commented Aug 12, 2021

Applied two fixes:

Hopefully when there are errors not they show up normally (even on current xdm).
The second error should now be fixed as well when I release in a minute!

@wooorm wooorm closed this as completed Aug 12, 2021
@kentcdodds
Copy link
Author

Super! Thank you 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants