code-surfer: `mdx-deck build` errors with "Cannot read property 'step' of null"

It seems mdx-deck build doesn’t work if I use CodeSurfer (regardless of how raw-loader is used)… I get this:

[mdx-deck] building
[mdx-deck] rendering static html
Missing HeadProvider
[err] TypeError: Cannot read property 'step' of null
    at _class2.render (./node_modules/mdx-deck-code-surfer/dist/deck-code-surfer.js:93:30)
    at processChild (./node_modules/react-dom/cjs/react-dom-server.node.development.js:2207:18)
    at resolve (./node_modules/react-dom/cjs/react-dom-server.node.development.js:2064:5)
    at ReactDOMServerRenderer.render (./node_modules/react-dom/cjs/react-dom-server.node.development.js:2383:22)
    at ReactDOMServerRenderer.read (./node_modules/react-dom/cjs/react-dom-server.node.development.js:2357:19)
    at renderToString (./node_modules/react-dom/cjs/react-dom-server.node.development.js:2729:25)
    at renderHTML (./node_modules/mdx-deck/lib/html.js:57:16)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 19 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@jxnblk Hi.

it might be related to mdx-deck’s use of webpack-node-externals

Maybe you’re right. I changed node_modules/mdx-deck/lib/html.js as here:

   config.externals = [
     nodeExternals({
       whitelist: [
         'mdx-deck',
         'mdx-deck/themes',
-        'mdx-deck/layouts'
+        'mdx-deck/layouts',
+        'mdx-deck-code-surfer'
       ]
     })
   ]

It works as expected but I didn’t understand why it worked.

Seems it’s an issue added in mdx-deck v1.6.6, same happens with the Appear component. I’ll create the issue there (edit: jxnblk/mdx-deck#138).

Workarounds: use mdx-deck v1.6.5 or use mdx-deck build --no-html your.mdx

After updates I get this error instead:

[err] TypeError: Cannot read property 'update' of null
    at new InnerCodeSurfer (node_modules/mdx-deck-code-surfer/dist/deck-code-surfer.js:60:30)
    ...

--no-html still works without error

Ah yeah… 😬 I think the root of the issue is with React context being a singleton, but code-surfer is not getting the same context in the mdx-deck build step.

The changes in jxnblk/mdx-deck#144 should hopefully help with that by exposing a public withDeck HOC in the API. I.e. if you use import { withDeck } from 'mdx-deck' with this new API, then it should be getting the same React context.

Definitely wanna make sure that code-surfer works well with mdx-deck and would love to get your thoughts on the proposed API changes

Fixed in v3

@spicydonuts the Notes bug should be fixed in mdx-deck-code-surfer v0.4.1

@trevordmiller I’m not sure how to fix mdx-deck build yet, as a workaround you can use mdx-deck build --no-html your.mdx

@jxnblk Hi.

it might be related to mdx-deck’s use of webpack-node-externals

Maybe you’re right. I changed node_modules/mdx-deck/lib/html.js as here:

   config.externals = [
     nodeExternals({
       whitelist: [
         'mdx-deck',
         'mdx-deck/themes',
-        'mdx-deck/layouts'
+        'mdx-deck/layouts',
+        'mdx-deck-code-surfer'
       ]
     })
   ]

It works as expected but I didn’t understand why it worked.

This actually Worked for me.Thanks @Leko

I’ve got this error

TypeError: Cannot read property 'update' of null
    at new InnerCodeSurfer (/Users/sibelius/Dev/app/slides/functional-types-abstraction/node_modules/mdx-deck-code-surfer/dist/deck-code-surfer.js:93:30)
    at processChild (/Users/sibelius/Dev/app/slides/functional-types-abstraction/node_modules/react-dom/cjs/react-dom-server.node.development.js:2750:14)
    at resolve (/Users/sibelius/Dev/app/slides/functional-types-abstraction/node_modules/react-dom/cjs/react-dom-server.node.development.js:2716:5)
    at ReactDOMServerRenderer.render (/Users/sibelius/Dev/app/slides/functional-types-abstraction/node_modules/react-dom/cjs/react-dom-server.node.development.js:3100:22)
    at ReactDOMServerRenderer.read (/Users/sibelius/Dev/app/slides/functional-types-abstraction/node_modules/react-dom/cjs/react-dom-server.node.development.js:3059:29)
    at renderToString (/Users/sibelius/Dev/app/slides/functional-types-abstraction/node_modules/react-dom/cjs/react-dom-server.node.development.js:3526:27)
    at renderHTML (/Users/sibelius/Dev/app/slides/functional-types-abstraction/node_modules/mdx-deck/lib/html.js:65:16)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

You can reproduce running yarn build on this presentation https://github.com/sibelius/functional-types-abstractions

@Leko your suggestion worked for me, thank you!