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

Storybook 6.2.0-beta.13 not transforming class properties #14197

Closed
anicholls opened this issue Mar 11, 2021 · 35 comments
Closed

Storybook 6.2.0-beta.13 not transforming class properties #14197

anicholls opened this issue Mar 11, 2021 · 35 comments

Comments

@anicholls
Copy link

anicholls commented Mar 11, 2021

I have tried to upgrade to 6.2.0-beta.13 to test the fix for #13608 and I am having babel issues. On start up I’m getting a bunch of Syntax Error: Missing class properties transform errors. However, it looks like @babel/plugin-proposal-class-properties is still included in the default storybook babel plugins so I don't know why this is appearing all of a sudden. Even if I explicitly add it myself in main.js I get the same error. I saw a couple babel changes in the changelog for 6.2, but nothing specifically related to this. It worked fine in 6.1.3.

To Reproduce
Steps to reproduce the behavior:

  1. Upgrade to @storybook/[email protected] with npx sb upgrade -p
  2. Use class properties in a component that is referenced in a story:
class MyComponent extends React.Component<MyComponentProps> {
  static Foo = Bar;
  // ...
}
  1. Start storybook

Expected behavior
The class properties should be transformed and Storybook should start normally.

Code snippets
Adding the following to main.js does not help.

  babel: async options => ({
    ...options,
    plugins: [...options.plugins, '@babel/plugin-proposal-class-properties'],
  }),

If you log options, you can see that the plugin is already provided so this shouldn't be needed anyway.

┆Issue is synchronized with this Asana task by Unito

@shilman
Copy link
Member

shilman commented Mar 11, 2021

@anicholls as a workaround can you try

  babelDefault: async options => ({
    ...options,
    plugins: [...options.plugins, '@babel/plugin-proposal-class-properties'],
  }),

we did a bunch of package upgrades in 6.2 so if you're not seeing any specific change about this, i'd bet it's due to something that happened in one of our dependencies?

@anicholls
Copy link
Author

@shilman Thanks! Switching from babel to babelDefault doesn't seem to make a difference.

@mgameover
Copy link

mgameover commented Mar 15, 2021

Hi guys,
I faced with the same issue after upgrading SB v6.1.11 → 6.2.0-rc.0. The suggested solution didn't work for me neither.

But I was managed to get rid of that error and run storybook by simply installing the following packages:

npm install --save-dev @babel/preset-typescript @babel/preset-env @babel/plugin-proposal-class-properties @babel/plugin-proposal-object-rest-spread

and deleting node_modules\.cache folder. @anicholls that might work for you.

However I am getting another error right now:

index.js:70 TypeError: Cannot convert undefined or null to object
    at getPrototypeOf (<anonymous>)
    at r.parse (vendors~main.ede20facac207df8bf21.bundle.js:475595)
    at Object.t.parse (vendors~main.ede20facac207df8bf21.bundle.js:475619)
    at Mn (vendors~main.ede20facac207df8bf21.bundle.js:475661)
    at Un (vendors~main.ede20facac207df8bf21.bundle.js:475850)
    at Object.parse (vendors~main.ede20facac207df8bf21.bundle.js:475896)
    at Object.parse (vendors~main.ede20facac207df8bf21.bundle.js:475966)
    at ts (vendors~main.ede20facac207df8bf21.bundle.js:475966)
    at us (vendors~main.ede20facac207df8bf21.bundle.js:475966)
    at vendors~main.ede20facac207df8bf21.bundle.js:475996
error @ index.js:70

any thoughts?

One more thing, I played with alpha versions and found out that the change was introduced in v6.2.0-alpha.15. There are no any errors with v6.2.0-alpha.14.

@hanwenbo
Copy link

still

@shilman
Copy link
Member

shilman commented Mar 16, 2021

It's gotta be something here #13631

Dependencies__6_2_non-breaking_package_upgrades_by_phated_·_Pull_Request__13631_·_storybookjs_storybook

Dependencies__6_2_non-breaking_package_upgrades_by_phated_·_Pull_Request__13631_·_storybookjs_storybook

@mgameover
Copy link

Hi guys,
Yes, the issue is sitting somewhere in dependencies... The following configuration works for me:

    "@babel/plugin-proposal-class-properties": "7.12.1",
    "@babel/plugin-proposal-object-rest-spread": "7.12.1",
    "@babel/preset-env": "7.12.11",
    "@babel/preset-typescript": "7.12.7",

    "@storybook/addon-a11y": "6.2.0-rc.1",
    "@storybook/addon-actions": "6.2.0-rc.1",
    "@storybook/addon-docs": "6.2.0-rc.1",
    "@storybook/addon-knobs": "6.2.0-rc.1",
    "@storybook/addon-links": "6.2.0-rc.1",
    "@storybook/addon-storysource": "6.2.0-rc.1",
    "@storybook/addon-viewport": "6.2.0-rc.1",
    "@storybook/addons": "6.2.0-rc.1",
    "@storybook/angular": "6.2.0-rc.1",
    "@storybook/source-loader": "6.2.0-rc.1",

What I did is:

  1. Completely removed node_modules folder and package-lock.json file
  2. added @babel/* and updated @storybook/* packages from the snippet above
  3. ran npm i

No issues so far.

@shilman
Copy link
Member

shilman commented Mar 22, 2021

Was unable to reproduce this in a fresh project. Does anybody have a repro repo they can share?

@PhekPR
Copy link

PhekPR commented Mar 23, 2021

Was unable to reproduce this in a fresh project. Does anybody have a repro repo they can share?

I think I managed to reproduce this. I removed and simplified as many files as possible from our design system where we currently have this problem when upgrading and then applied the Storybook upgrade guide on it.

Here is the repo:
https://github.com/PhekPR/reprod-storybook-transforming-class-properties

Sorry if there's many unnecessary dependencies. I tried to not touch them too much since the problem seem to be related to dependencies

@cinan
Copy link

cinan commented Mar 24, 2021

I had the same problem with storybook 6.2.0-rc.9. Solved by yarn dedupe (yarn 2.4.1)

@darkowic
Copy link

In my case, I was able to make it work by forcing "@babel/plugin-proposal-class-properties": "~7.10.1",. This may be also because we have a babel mess in our monorepo. The babel v7.11 or 7.12 is causing many problems.

@shilman
Copy link
Member

shilman commented Mar 26, 2021

@PhekPR is there any chance you can update your project to use the Yarn or NPM registry? Currently your lockfile is pointing at pricerunner.info, which I don't have access to. Also please remove eslint-config-pricerunner which looks unused in the repo and is not public. Many thanks!

@shilman
Copy link
Member

shilman commented Mar 26, 2021

For those of you running into this, is it fixed if you remove node_modules and lockfile and reinstall?

@PhekPR
Copy link

PhekPR commented Mar 29, 2021

@PhekPR is there any chance you can update your project to use the Yarn or NPM registry? Currently your lockfile is pointing at pricerunner.info, which I don't have access to. Also please remove eslint-config-pricerunner which looks unused in the repo and is not public. Many thanks!

Ah of course. I missed one of them, thought I removed them all. It should now be fixed!

@shilman
Copy link
Member

shilman commented Mar 29, 2021

@PhekPR hey, the lockfile still points to https://nexus.pricerunner.info, any chance you can fix it? If I blow away the lockfile I believe it solves the problem, but I want to repro if possible.

@PhekPR
Copy link

PhekPR commented Mar 29, 2021

@PhekPR hey, the lockfile still points to https://nexus.pricerunner.info, any chance you can fix it? If I blow away the lockfile I believe it solves the problem, but I want to repro if possible.

Ahh. Of course 🤦‍♂️
Yes if I blow away the lockfile I get a different error, probably some changed versions. I tried replacing the registry now in the lock file to the default one. Seem to reproduce the correct error. Hope it works on your end now also

@anicholls
Copy link
Author

@shilman I don't have a stripped down repro repo, but it is reproducible on our component library: https://github.com/Workday/canvas-kit. All dependencies use the yarn registry. Ideally we'd avoid blowing away our lockfile.

@andreiho
Copy link

andreiho commented Apr 6, 2021

@anicholls I fixed it by specifically removing only the @babel/plugin-proposal-class-properties entries in the lockfile, then re-installing. Before there were about 5 different version resolutions for that package.

@artaommahe
Copy link

artaommahe commented Apr 8, 2021

caught this bug after updating 6.2.0-alpha.24 -> 6.2.5 😕 6.2.0-rc.1 works well though
(but with RangeError: Maximum call stack size exceeded, doesn't break anything as i see)

@artaommahe
Copy link

artaommahe commented Apr 9, 2021

Debugged a little more

Looks like this pr breaks everything #14047

@shilman

@hipstersmoothie
Copy link
Contributor

Running the following fixed it for me:

npx yarn-deduplicate --scopes @babel

@artaommahe
Copy link

artaommahe commented Apr 20, 2021

@shilman @hipstersmoothie I've reproduced Cannot convert undefined or null to object error with the new ng application and our real package.json/yarn.lock minimal crop. Somehow it looks related to @storybook/addon-docs usage

https://github.com/artaommahe/storybook-issue14197

"@storybook/addon-docs": "6.2.8",
"@storybook/angular": "6.2.8",

Tried these things, no one helped

  • npx yarn-deduplicate --scopes @babel
  • "@babel/plugin-proposal-class-properties": "~7.10.1" (added to resolutions)
  • "@babel/plugin-proposal-class-properties": "7.13.0" (added to resolutions)
  • updating angular libs to last versions

But this one helps (can be reproduced with this repo)

  • rm yarn.lock
  • yarn install

Can't find what lib to update to solve this 😕(removing yarn.lock and updating all libs in our monorep is not a way, too much to test/fix/break)

@adambrgmn
Copy link

I just encountered the same issue. And I might not have found a solution but a potential cause of the issue.
Since v7.14.0 @babel/preset-env automatically includes the class properties transform. But in our case we rely on a babel preset with @babel/preset-env v7.12.1, which does not include the class properties transform.

I have very scarce knowledge of how, in our case, yarn works with multiple versions of the same dependency. But running yarn why @babel/preset-env shows that I have a few different version in my project.

I could use yarn resolutions and force the version. But this is causing ripples into the other projects.

As mentioned not a solution but a possible cause.

@shilman
Copy link
Member

shilman commented May 18, 2021

Thank you @adambrgmn -- much appreciated!! 🙏

@Domiii
Copy link

Domiii commented May 30, 2021

As pointed out by @adambrgmn, the latest babel version introduces some changes that don't work well with old versions. Making sure to have consistent dependencies is a must here.

In my case it was references to older babel versions, in conflict with newer versions used by storybook that caused the issue

NOTE: Once updated, storybook works again, but will spit out some warnings about the loose option. I'm sure the team will fix this soon enough.

Steps taken

  1. Make sure your package.json does not reference outdated versions of @babel/core and friends.
  2. Find a consistent way to upgrade all packages in any project setup (which is just really difficult to do)

I got it to work by taking the nuclear option of deleting yarn.lock and all node_modules folders in my monorepo.

Of course, locking corresponding babel references to the right version avoids nuking your node_modules.

@shilman
Copy link
Member

shilman commented May 30, 2021

@Domiii Try upgrading to the latest prerelease:

npx sb@next upgrade --prerelease

I think we've already got a fix in

@shilman
Copy link
Member

shilman commented Jun 8, 2021

Closing this as fixed in 6.3

@shilman shilman closed this as completed Jun 8, 2021
@imbhargav5
Copy link

@shilman Issue still persists in 6.3. 😞

@ankitghosh
Copy link

It was happening to us also for 6.1 version, upgrading it to 6.3 fixed the issue. @imbhargav5 may be try deleting node_modules and storybook cache and try again.

@imbhargav5
Copy link

Will try it 👍

@mayank99
Copy link
Contributor

Closing this as fixed in 6.3

@shilman I upgraded to 6.3.4, cleared node_modules and cache, and I was still getting this issue:

SyntaxError: \path\to\Component.tsx Missing class properties transform.
  17 |
  18 | export default class Component{
> 19 |   private someProps: ComponentProps[] = [];

Adding this to main.js fixed it:

  babel: async (options) => ({
    ...options,
    plugins: [['@babel/plugin-proposal-class-properties', { loose: true }]],
  }),

Should I open a new issue?

@liby
Copy link

liby commented Aug 11, 2021

@shilman Encountered this issue in the latest version.

Environment Info
  System:
    OS: macOS 11.2.1
    CPU: (12) x64 Intel(R) Core(TM) i5-10500 CPU @ 3.10GHz
  Binaries:
    Node: 14.15.5 - ~/.nvs/default/bin/node
    Yarn: 1.22.10 - ~/.nvs/default/bin/yarn
    npm: 6.14.11 - ~/.nvs/default/bin/npm
  Browsers:
    Chrome: 92.0.4515.131
    Safari: 14.0.3
  npmPackages:
    @storybook/addon-a11y: ^6.3.7 => 6.3.7
    @storybook/addon-actions: ^6.3.7 => 6.3.7
    @storybook/addon-console: ^1.2.3 => 1.2.3
    @storybook/addon-essentials: ^6.3.7 => 6.3.7
    @storybook/addon-links: ^6.3.7 => 6.3.7
    @storybook/addon-storysource: ^6.3.7 => 6.3.7
    @storybook/addons: ^6.3.7 => 6.3.7
    @storybook/builder-webpack5: ^6.3.7 => 6.3.7
    @storybook/manager-webpack5: ^6.3.7 => 6.3.7
    @storybook/react: ^6.3.7 => 6.3.7
yarn why @babel/preset-env
❯ yarn why @babel/preset-env
yarn why v1.22.10
[1/4] 🤔  Why do we have the module "@babel/preset-env"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "@babel/[email protected]"
info Has been hoisted to "@babel/preset-env"
info This module exists because it's specified in "devDependencies".
info Disk size without dependencies: "28.5MB"
info Disk size with unique dependencies: "809.64MB"
info Disk size with transitive dependencies: "1019MB"
info Number of shared dependencies: 144
=> Found "@storybook/builder-webpack5#@babel/[email protected]"
info This module exists because "@storybook#builder-webpack5" depends on it.
info Disk size without dependencies: "13.94MB"
info Disk size with unique dependencies: "795.01MB"
info Disk size with transitive dependencies: "1004.36MB"
info Number of shared dependencies: 140
=> Found "@cypress/webpack-preprocessor#@babel/[email protected]"
info This module exists because "@bahmutov#add-typescript-to-cypress#@cypress#webpack-preprocessor" depends on it.
info Disk size without dependencies: "264KB"
info Disk size with unique dependencies: "432.71MB"
info Disk size with transitive dependencies: "593.54MB"
info Number of shared dependencies: 119
=> Found "@storybook/addon-docs#@babel/[email protected]"
info This module exists because "@storybook#addon-essentials#@storybook#addon-docs" depends on it.
info Disk size without dependencies: "160KB"
info Disk size with unique dependencies: "781.22MB"
info Disk size with transitive dependencies: "990.58MB"
info Number of shared dependencies: 140
=> Found "@storybook/core-common#@babel/[email protected]"
info This module exists because "@storybook#react#@storybook#core-common" depends on it.
info Disk size without dependencies: "36.02MB"
info Disk size with unique dependencies: "817.09MB"
info Disk size with transitive dependencies: "1GB"
info Number of shared dependencies: 140
=> Found "@storybook/builder-webpack4#@babel/[email protected]"
info This module exists because "@storybook#addon-essentials#@storybook#addon-docs#@storybook#builder-webpack4" depends on it.
info Disk size without dependencies: "36.05MB"
info Disk size with unique dependencies: "817.11MB"
info Disk size with transitive dependencies: "1GB"
info Number of shared dependencies: 140
=> Found "@storybook/csf-tools#@babel/[email protected]"
info This module exists because "@storybook#addon-essentials#@storybook#addon-docs#@storybook#csf-tools" depends on it.
info Disk size without dependencies: "1.56MB"
info Disk size with unique dependencies: "782.63MB"
info Disk size with transitive dependencies: "991.98MB"
info Number of shared dependencies: 140
✨  Done in 32.07s.

@mayank99 The method mentioned has given me some help. This is done by explicitly listing the babel configuration in the main.js file without doing anything else and without return anything, which solves my issue.

  // It’s working
  babel: () => {},
  
  // Does not help
  babel: async (options) => ({
    ...options,
    plugins: [['@babel/plugin-proposal-class-properties', { loose: true }]],
  }),

@leotm
Copy link

leotm commented Aug 23, 2021

jus curious why/how #14197 (comment) resolves

when our babel.config.js preset module:metro-react-native-babel-preset main.js includes it

// ...
const defaultPluginsBeforeRegenerator = [
  // ...
  [
    require('@babel/plugin-proposal-class-properties'),
    // use `this.foo = bar` instead of `this.defineProperty('foo', ...)`
    {loose: true},
  ],
  // ...
  ...passthroughSyntaxPlugins,
];
// ...
return {
// ...
overrides: [
      // the flow strip types plugin must go BEFORE class properties!
      // there'll be a test case that fails if you don't.
      {
        plugins: [require('@babel/plugin-transform-flow-strip-types')],
      },
      {
        plugins: [
          ...defaultPluginsBeforeRegenerator,
          isHermes ? null : require('@babel/plugin-transform-regenerator'),
          ...defaultPluginsAfterRegenerator,
        ].filter(Boolean),
      },
// ...

purely speaking from theory, still on ye ole v5

@shilman
Copy link
Member

shilman commented Oct 22, 2021

For anybody stumbling on this issue, we still don't have a root cause. Given all the comments above, it appears that multiple versions of babel and its various packages are not working well together. Given that, clearing those out of the lockfile and reinstalling forces all the babel libs to the same version, which solves the problem.

Things to try (in order of least to most disruptive):

  • try upgrading to the latest storybook npx sb upgrade
  • npx yarn-deduplicate --scopes @babel
  • try updating your .storybook/main.js with the snippet below
  • try removing your lockfile and reinstalling
// main.js
module.exports = {
  babel: async (options) => ({
    ...options,
    plugins: [['@babel/plugin-proposal-class-properties', { loose: true }]],
  }),
}

@dwwr
Copy link

dwwr commented Apr 11, 2022

@shilman Thanks for the snippet!

@movy
Copy link

movy commented Nov 29, 2023

For the 3rd time I've come across this problem, it happens about every other time I upgrade dev-packages, especially babel-related stuff. As I keep returning here from google, will leave this note for future self.

None of the snippets above helped, but what really helps is clearing ALL yarn caches, i.e. local project cache at .yarn/cache and also home dir cache at ~/.yarn/berry/cache. I guess similar applies to npm.. any node_modules up the folder tree will potentially srew something up during upgrade, so all requires wiping out.

And yes, all babel-* modules better be exact same version, e.g:

    "@babel/core": "^7.22.9",
    "@babel/preset-env": "^7.22.9",
    "@babel/preset-typescript": "^7.22.9",
    "@babel/runtime": "^7.22.9",
    "@babel/runtime-corejs3": "^7.22.9",

None of babel plugins apart from preset-env were required or helped me to fix this.

Amazing we're still facing this in December 2023, module management should be top-notch by now..

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