mdx: toJSX does not have a default for `options.file`

Subject of the issue

After the most recent release, Storybook will not build and returns this error:

WARN ./src/components/Box/Box.stories.mdx
WARN Module build failed (from ./node_modules/@mdx-js/loader/index.js):
WARN TypeError: Cannot read property 'path' of undefined
WARN     at Function.toJSX (project/node_modules/@storybook/addon-docs/node_modules/@mdx-js/mdx/mdx-hast-to-jsx.js:124:30)
WARN     at extractExports (project/node_modules/@storybook/addon-docs/dist/mdx/mdx-compiler-plugin.js:396:29)
WARN     at Compiler (project/node_modules/@storybook/addon-docs/dist/mdx/mdx-compiler-plugin.js:454:14)
WARN     at Function.stringify (project/node_modules/unified/index.js:354:12)
WARN     at pipelineStringify (project/node_modules/unified/index.js:41:18)
WARN     at wrapped (project/node_modules/trough/wrap.js:25:19)
WARN     at next (project/node_modules/trough/index.js:57:24)
WARN     at done (project/node_modules/trough/wrap.js:55:16)
WARN     at done (project/node_modules/unified/index.js:35:7)
WARN     at done (project/node_modules/unified/index.js:314:11)
WARN     at next (project/node_modules/trough/index.js:59:14)
WARN     at done (project/node_modules/trough/wrap.js:55:16)
WARN     at then (project/node_modules/trough/wrap.js:62:5)
WARN     at wrapped (project/node_modules/trough/wrap.js:45:9)
WARN     at next (project/node_modules/trough/index.js:57:24)
WARN     at done (project/node_modules/trough/wrap.js:55:16)
WARN  @ ./src/components/Box sync nonrecursive ^\.\/(?:(?:Box\.stories\.mdx)$)$ ./Box.stories.mdx
WARN  @ ./.storybook/generated-entry.js
WARN  @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./node_modules/@storybook/addon-docs/dist/frameworks/common/config.js ./node_modules/@storybook/addon-docs/dist/frameworks/react/config.js ./.storybook/preview.js ./.storybook/generated-entry.js

This might be Storybook’s issue to solve, but it also seems as if there isn’t a defaulting occurring for options.file inside of toJSX() here, which was introduced in #1126.

Your environment

  • OS: OSX 10.15.5
  • Packages: @storybook/addon-docs ^5.3.13, @storybook/react ^5.3.13
  • Env: lerna + yarn

Steps to reproduce

  1. Have a .stories.mdx file in a storybook build
  2. execute the build-storybook script that Storybook ships with

Expected behaviour

Storybook builds

Actual behaviour

Storybook fails building with the above error

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 29 (14 by maintainers)

Most upvoted comments

Released 1.6.11 🚀

@silvenon tested with Storybook 5.3.19 I can confirm version 1.6.11 fixed the issue.

Same here! Thanks for your help everyone!

Thanks so much for the fix. If it’s fine by you, we’ll make the fix on the Storybook side (along with any other breaking fixes needed) when MDX 2.0 drops. Really looking forward to that—you guys are doing amazing work!!!

I hit this same thing and same as @owenallenaz, if I force 1.6.7 the warning in the description goes away, and I’m able to view mdx stories in Storybook. Just in case anyone else is hitting this, to continue working I’m adding a resolutions block to my package.json to force the previous version.

"resolutions": {
    "@mdx-js/loader": "1.6.7",
    "@mdx-js/mdx": "1.6.7",
    "@mdx-js/react": "1.6.7",
    "@mdx-js/util": "1.6.7"
  }

I’m using Yarn. Not sure if that same thing works with npm or not.

Thanks @RoachaelRoadmunk for reporting this issue.

The latest version should now fix it. Please let us know if that isn’t the case. Thanks all!

@johno It didn’t 😭 I went ahead and tested it and got a fix. PR is here

Hopefully 1.6.10 addresses it now 😆.

After some more investigation… I am more convinced it is actually related to the commit I referenced.

In there, filename: options.file.path is added in several places. When I modified the file (mdx-hast-to-jsx.js) locally to filename: options.filepath the error was resolved.

I believe the wrong option is possibly being selected. options.file does not appear to be part of the options object that is passed.

@johno It didn’t 😭 I went ahead and tested it and got a fix. PR is here

Yes!! I tested this in my repo and looks like it will be the solution for me as well! Thanks @dustinsavery and everyone else with their help as well! Ship it 😃

Ah, yeah we need to more gracefully handle null for file. I’ll have a fix in a few, thanks for reporting!

I am experiencing the exact same issue. When I update my package.json to add the following to my package.json dependencies object the issue goes away.

"@mdx-js/loader": "1.6.7",
"@mdx-js/mdx": "1.6.7",
"@mdx-js/react": "1.6.7",

So I think it is definitely related to 1.6.8. Now it might be in the way that @storybook/addon-docs uses it.