question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regression in babel transpilation

See original GitHub issue

Same as #11045, which was closed as fixed. I re-tested under beta.36, same issue is present.

Describe the bug

The following transpiled fine in 5.x:

export class ClassWithTranspilationIssues {
  constructor(private configuration: any = { foo: 'bar' }) { }

  printConfigParameter(): void {
    console.log(this.configuration.foo);
  }
}

It no longer transpiles correctly with Storybook 6:

new ClassWithTranspilationIssues().printConfigParameter() // => Unexpected error: TypeError: Cannot read property 'foo' of undefined

To reproduce:

Expected behavior

Constructor parameters with default values should be transpiled correctly.

System:

  System:
    OS: Linux 5.7 Arch Linux
    CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
  Binaries:
    Node: 14.4.0 - /tmp/yarn--1593089574779-0.009958780001808165/node
    Yarn: 1.22.4 - /tmp/yarn--1593089574779-0.009958780001808165/yarn
    npm: 6.14.5 - /usr/sbin/npm
  Browsers:
    Firefox: 77.0.1
  npmPackages:
    @storybook/addon-actions: ^6.0.0-beta.36 => 6.0.0-beta.36 
    @storybook/addon-links: ^6.0.0-beta.36 => 6.0.0-beta.36 
    @storybook/addons: ^6.0.0-beta.36 => 6.0.0-beta.36 
    @storybook/cli: ^6.0.0-beta.36 => 6.0.0-beta.36 
    @storybook/preset-create-react-app: ^3.0.0 => 3.0.0 
    @storybook/react: ^6.0.0-beta.36 => 6.0.0-beta.36 

Additional context

The issue is related to the order in which babel plugins run. I fixed this locally in storybook/lib/core/src/server/common/babel.js:

The clue was in https://github.com/babel/babel/pull/8682#issuecomment-420408858

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bardcommented, Jul 9, 2020

I hacked around this in the code base I’m working. Here’s the summary in case someone finds this through a search.

  • If your project was created with create-react-app and you’re using @storybook/preset-create-react-app, you shouldn’t need to worry about anything, because project and Storybook will be using compatible webpack configurations.
  • If you’re adding Storybook to an existing project with a custom webpack config, you might run into situations where code transpiles fine for your project but not for Storybook, due to Storybook’s defaults differing for your custom webpack config.
  • This may be especially insidious if your project is stuck with ts-loader because e.g. your project won’t run with babel-loader due to --isolatedModules.
  • The following hack in .storybook/main.js fixed things in my case. It discards Storybook’s default rules, except for MDX ones, and replaces them with local rules.
module.exports = {
    stories: [
        '../src/**/*.stories.tsx'
    ],
    addons: [
        '@storybook/addon-essentials'
    ],
    webpackFinal: async config => {
    
        const storybookWebpackMdxRules = config.module.rules.filter(r => {
            return (
                r.test.test('example.mdx') ||
                r.test.test('example.stories.mdx')
            )
        })

        config.module.rules = [
            ...storybookWebpackMdxRules,
            ...require('../webpack.config').module.rules
        ]

        return config
    }
}
0reactions
stale[bot]commented, Oct 12, 2020

Hey there, it’s me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Babel Roadmap
This will give us a few things: Better confidence in Babel's output. More tests/coverage is better for catching regressions and finding spec bugs...
Read more >
Should a thrown error in babel-transpiled code show the ...
Yes, this is expected behavior. Stacktrace behavior isn't part of the ES6 spec, it's more of a defacto standard that has been settled...
Read more >
CoffeeScript
-t, --transpile, Pipe the CoffeeScript compiler's output through Babel ... Bugfix for regression in 2.2.0 involving an error thrown by the compiler in ......
Read more >
babel-preset-edge - npm Package Health Analysis | Snyk
The preset does not offer the translation of generators nor transpilation of async/await to these. This has always been a half-baked solution with...
Read more >
babel-loader | Yarn - Package Manager
v6.2.7. Regression ... Fixes an issue with v6.2.6 when using babel-loader as a global package. v6.2.6. Bug Fix ... Use the common cache...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found