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

Incorrect typesVersions in @storybook/* packages cause build errors with older TS versions #15196

Closed
EliHowey opened this issue Jun 10, 2021 · 1 comment

Comments

@EliHowey
Copy link

Describe the bug
I have an Angular 9 Storybook running on TypeScript v3.6.5. I recently tried to upgrade Storybook from v6.1.3 to v6.3.0-rc.0, but ran into a TS compilation error in every file that imported a @storybook package: Cannot find module '@storybook/*'

I was able to trace the issue to the typesVersions listed in each package's package.json. Currently, each package lists something like the following:

"types": "dist/ts3.9/index.d.ts",
"typesVersions": {
  "<3.8": {
    "*": [
      "dist/ts3.4/*"
    ]
  }
}

When TypeScript resolves file paths using typesVersions, it substitutes the entire matching glob in the replacement glob. In this case, dist/ts3.9/index.d.ts matches the search glob *, so it maps that to dist/ts3.4/dist/ts3.9/index.d.ts, rather than dist/ts3.4/index.d.ts.

Changing the typesVersions to the following fixes the errors:

"typesVersions": {
  "<3.8": {
    "dist/ts3.9/*": [
      "dist/ts3.4/*"
    ]
  }
}

To Reproduce
I haven't created a minimal reproduction, but I'd expect this to affect any Storybook project using a TypeScript version earlier than v3.8.

System

Environment Info:

  System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 12.22.0 - ~/.nvm/versions/node/v12.22.0/bin/node
    npm: 6.14.11 - ~/.nvm/versions/node/v12.22.0/bin/npm
  Browsers:
    Chrome: 91.0.4472.77
    Edge: 91.0.864.41
    Firefox: 89.0
    Safari: 14.1.1
  npmPackages:
    @storybook/addon-a11y: 6.3.0-rc.0 => 6.3.0-rc.0 
    @storybook/addon-docs: 6.3.0-rc.0 => 6.3.0-rc.0 
    @storybook/addon-essentials: 6.3.0-rc.0 => 6.3.0-rc.0 
    @storybook/addon-knobs: 6.2.9 => 6.2.9 
    @storybook/addons: 6.3.0-rc.0 => 6.3.0-rc.0 
    @storybook/angular: 6.3.0-rc.0 => 6.3.0-rc.0 
    @storybook/builder-webpack5: 6.3.0-rc.0 => 6.3.0-rc.0 
    @storybook/manager-webpack5: 6.3.0-rc.0 => 6.3.0-rc.0 

Additional context

@shilman
Copy link
Member

shilman commented Aug 31, 2021

Huzzah!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.4.0-alpha.33 containing PR #15918 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants