Skip to content

Avoid buggy getProjectRoot()#14

Merged
valentinpalkovic merged 2 commits intostorybookjs:mainfrom
ddadamhooper:adam.hooper/nix-get-project-root
Apr 1, 2025
Merged

Avoid buggy getProjectRoot()#14
valentinpalkovic merged 2 commits intostorybookjs:mainfrom
ddadamhooper:adam.hooper/nix-get-project-root

Conversation

@ddadamhooper
Copy link
Copy Markdown
Contributor

@ddadamhooper ddadamhooper commented Mar 28, 2025

[closes storybookjs/storybook/issues/14042]

Storybook fails to compile TypeScript when I use git worktrees and yarn.

This setup has two interesting properties:

  • git worktrees don't have a .git/ directory.
  • Yarn doesn't put any code in node_modules/.

So getProjectRoot() doesn't find my top-level directory via either path. But it does find a node_modules/! There's a node_modules inside the addon-webpack5-compiler-babel folder. So getProjectRoot() returns, "/home/adam.hooper/src/myproject/.yarn/cache/@storybook-addon-webpack5-compiler-babel-npm-3.0.5-9ba7eaab05-32249b0dbf.zip/". And my TypeScript files outside of that directory don't match the include, so they don't get compiled.

Workaround: STORYBOOK_PROJECT_ROOT=/ yarn storybook can get Storybook up and running.

Solution: heck, why do we have "include" in the first place? It looks like it's designed to translate all files; and we'll get the same effect if we simply remove it. This PR removes it.

Side-effects: now the babel loader ignores STORYBOOK_PROJECT_ROOT. That env variable isn't documented, and it's unlikely somebody out there uses STORYBOOK_PROJECT_ROOT to filter out files for Babel translation.

@valentinpalkovic
Copy link
Copy Markdown
Contributor

Hi @ddadamhooper

Thank you for opening the PR!

why do we have "include" in the first place? It looks like it's designed to translate all files, and we'll get the same effect if we simply remove it. This PR removes it.

That's an excellent question. Unfortunately, I can't recall its existence. Let's remove it and see how this change is affecting others. But I think it is reasonable to remove it!

@valentinpalkovic valentinpalkovic self-assigned this Mar 28, 2025
@valentinpalkovic valentinpalkovic added the patch Increment the patch version when merged label Mar 28, 2025
@valentinpalkovic
Copy link
Copy Markdown
Contributor

fyi: I will merge and release a patch on Monday!

@ddadamhooper
Copy link
Copy Markdown
Contributor Author

@valentinpalkovic Thank you!

The same code does the same thing in addon-webpack5-compiler-swc, by the way.

@valentinpalkovic
Copy link
Copy Markdown
Contributor

valentinpalkovic commented Mar 31, 2025

I've pinged a college of mine to ask for a second opinion. Hopefully, we can get it merged asap!

@valentinpalkovic valentinpalkovic merged commit 97a74e1 into storybookjs:main Apr 1, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Increment the patch version when merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build issue with yarn 2 when not in git or svn context

3 participants