Storybook: [StoryShots] unexpected identifier global in storyshots after upgrade.

Created on 21 Nov 2019  路  3Comments  路  Source: storybookjs/storybook

After upgrading my storybook to 5.3.beta.3 and configuring docgen with typescript. My storyshots have stopped working. throwing this error every time i run them.
image

I have seen that this is not a new issue, however, I was not able to find any previous solutions to this problem.

My webpack config:

const path = require("path");
const styleguideContext = path.dirname(require.resolve('@logz-ui/styleguide'));
const { jsRule, tsRule, storyRule, cssRule  } = require('@logz-build/webpack');
const { browserProdConfig } = require('@logz-build/babel-config');

const ignoredProps = ['as', 'css', 'theme', 'ref'];

const storybookDocGenRule = () => ({
  test: /\.(tsx|ts)?$/,
  use: [
    {
      loader: require.resolve('react-docgen-typescript-loader'),
      options: {
        propFilter: prop => {
          if (ignoredProps.includes(prop.name)) {
            return false;
          }

          if (prop.parent) {
            return (
              !prop.parent.fileName.includes('node_modules/@types/react/') &&
              !prop.parent.fileName.includes('@types/styled-system')
            );
          }

          return true;
        },
      },
    },
  ],
  exclude: /node_modules/,
});

module.exports = ({ config }) => {
  config.context = (path.join(__dirname, '../'));

  config.module.rules =[
    tsRule({configFileName: path.join(__dirname, '../tsconfig.json'),
    include: [path.join(__dirname, '../stories')]}),
    storybookDocGenRule(),
    jsRule(browserProdConfig),
    storyRule,
    cssRule,
    config.module.rules[1]];

  config.resolve.extensions.push(".ts", ".tsx");

  config.resolve.alias = {
    '@logz-ui/styleguide': path.resolve(styleguideContext)
  };
  return config;
};

My storybook config

import React from 'react';
import { configure, addDecorator } from '@storybook/react';
import { withOptions } from '@storybook/addon-options';
import { withKnobs } from '@storybook/addon-knobs';
import { bootstrap } from '@logz-ui/styleguide';
import {StoryContainer} from "../stories/storyComponents/StoryContainer";

bootstrap();

const storyBookDecorators = [
  withKnobs,
  withOptions({
    name: `@logz-ui/styleguide`,
    url: 'https://github.com/logzio/gaia-hermes-ws/tree/master/styleguide',
    hierarchyRootSeparator: /\|/,
  }),
];

addDecorator(Story =>
  <StoryContainer>
    <Story />
  </StoryContainer>
);

storyBookDecorators.forEach(addon => addDecorator(addon));

configure(require.context('../stories', true, /\.story\.(jsx|ts|js|tsx)?$/), module);

My Presets:

const path = require("path");

module.exports = [
  {
    name: '@storybook/addon-docs/react/preset',
    options: {
      configureJSX: true,
      babelOptions: {
        babelrc: path ,
        presets: [],
        plugins: ['emotion'],
      },
      sourceLoaderOptions: null,
    },
  },
  {
    name: "@storybook/preset-typescript",
    options: {
      tsDocgenLoaderOptions: {
        tsconfigPath: path.resolve(__dirname, "../tsconfig.json")
      },
      include: [path.resolve(__dirname, "../stories")]
    }
  }
];

Would love to know how i can avoid this since it is blocking our upgrade to the new docgen feature.

storyshots bug question / support

All 3 comments

@Hypnosphi @ndelangen any recent storyshots changes that might lead to this problem?

It's probably the TS migration
cc @gaetanmaisse

Do we really need to include original .ts files in dist? Shouldn't .js + .d.ts be enough?

Hurrah!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.0-beta.10 containing PR #8971 that references this issue. Upgrade today to try it out!

You can find this prerelease on the @next NPM tag.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shilman picture shilman  路  3Comments

sakulstra picture sakulstra  路  3Comments

tomitrescak picture tomitrescak  路  3Comments

wahengchang picture wahengchang  路  3Comments

tlrobinson picture tlrobinson  路  3Comments