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

toJSX does not have a default for options.file #1153

Closed
RoachaelRoadmunk opened this issue Jul 16, 2020 · 29 comments · Fixed by #1154
Closed

toJSX does not have a default for options.file #1153

RoachaelRoadmunk opened this issue Jul 16, 2020 · 29 comments · Fixed by #1154
Labels
🏡 area/internal This affects the hidden internals

Comments

@RoachaelRoadmunk
Copy link

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

@RoachaelRoadmunk RoachaelRoadmunk added 🐛 type/bug This is a problem 🙉 open/needs-info This needs some more info labels Jul 16, 2020
@wooorm
Copy link
Member

wooorm commented Jul 16, 2020

This sounds like a storybook problem to me? 🤔 maybe you'll have better luck asking those folks?

@RoachaelRoadmunk
Copy link
Author

RoachaelRoadmunk commented Jul 16, 2020

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.

@owenallenaz
Copy link

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.

@wooorm
Copy link
Member

wooorm commented Jul 16, 2020

/cc @silvenon

@tylergaw
Copy link

tylergaw commented Jul 16, 2020

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.

@johno
Copy link
Member

johno commented Jul 16, 2020

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

@johno
Copy link
Member

johno commented Jul 16, 2020

This should now be fixed in version 1.6.9. Please let us know if that doesn't work. Thanks!

@dusave
Copy link

dusave commented Jul 16, 2020

@johno Issue still seems to be there, same error.
image

Confirmed the upgrade to 1.6.9

@johno
Copy link
Member

johno commented Jul 16, 2020

Hrmmm. Bummer! Thanks for checking @dustinsavery

Could someone perhaps provide a reproduction so I can debug this more deeply?

@johno johno reopened this Jul 16, 2020
@johno
Copy link
Member

johno commented Jul 16, 2020

I’m guessing the file argument must be coming in as null rather than undefined.

@dusave
Copy link

dusave commented Jul 16, 2020

It's called from here

@dusave
Copy link

dusave commented Jul 16, 2020

@johno Could you conditionally add the filename property here if one is given? Either that or perhaps doing some null/undefined checks or optional chaining to verify the property exists?

@johno
Copy link
Member

johno commented Jul 16, 2020

Either that or perhaps doing some null/undefined checks or optional chaining to verify the property exists?

We should definitely add that, but right now the MDX core package isn't transpiled and we support older versions of node that don't have optional changing.

I've opened up another PR which will hopefully address more falsy edge cases.

@johno
Copy link
Member

johno commented Jul 17, 2020

Hopefully 1.6.10 addresses it now 😆.

@dusave
Copy link

dusave commented Jul 17, 2020

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

@JounQin
Copy link
Member

JounQin commented Jul 17, 2020

@johno 1.6.10 won't work because toJSX is called inside storybook source.

@RoachaelRoadmunk
Copy link
Author

RoachaelRoadmunk commented Jul 17, 2020

@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 :)

@RoachaelRoadmunk
Copy link
Author

RoachaelRoadmunk commented Jul 17, 2020

@johno 1.6.10 won't work because toJSX is called inside storybook source.

@tylergaw's suggestion of adding the desired version to resolutions worked for me to override storybook @JounQin, in case that helps you!

@filipesperandio
Copy link

I've added the resolutions to 1.6.10 and I still get issues in storybook

Screen Shot 2020-07-17 at 01 37 24

@filipesperandio
Copy link

Forcing resolution back to 1.6.6 fixes it

@JounQin
Copy link
Member

JounQin commented Jul 17, 2020

@mdx-js/mergers A patch version need to be released.

@silvenon
Copy link
Contributor

Released 1.6.11 🚀

@johno
Copy link
Member

johno commented Jul 17, 2020

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

@johno johno closed this as completed Jul 17, 2020
@silvenon
Copy link
Contributor

silvenon commented Jul 17, 2020

I just want to add that toJSX is (currently) internal API. We didn't document it and we don't test it as a plugin, we only test it implicitly through mdx.

@wooorm
Copy link
Member

wooorm commented Jul 17, 2020

Yeah, want to second @silvenon. It’s an internal function that Storybook is depending on. So while the exception is now gone, Storybook should still provide a virtual file, and It’ll all change again completely in next!

@pvds
Copy link

pvds commented Jul 17, 2020

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

@shilman
Copy link

shilman commented Jul 17, 2020

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!!!

@RoachaelRoadmunk
Copy link
Author

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

Same here! Thanks for your help everyone!

@ghost
Copy link

ghost commented Jul 17, 2020

Thanks @RoachaelRoadmunk for reporting this issue.

@wooorm wooorm added 🏡 area/internal This affects the hidden internals and removed 🐛 type/bug This is a problem 🙉 open/needs-info This needs some more info labels Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏡 area/internal This affects the hidden internals
Development

Successfully merging a pull request may close this issue.