简体   繁体   English

故事书错误无法读取未定义的属性“位置”

[英]Storybook error Cannot read property 'location' of undefined

I'm trying to get my Storybook working with my React app.我正在尝试让我的 Storybook 与我的 React 应用程序一起工作。 I'm using redux 4.0.1.我正在使用 redux 4.0.1。

I can't use a particular component where I also use redux.我不能使用也使用 redux 的特定组件。 This is the error I'm getting:这是我得到的错误:

Storybook error Cannot read property 'location' of undefined故事书错误无法读取未定义的属性“位置”


This is my my devDependencies :这是我的devDependencies

  "devDependencies": {
    "@babel/core": "^7.10.0",
    "@storybook/addon-actions": "^5.3.19",
    "@storybook/addon-links": "^5.3.19",
    "@storybook/addons": "^5.3.19",
    "@storybook/react": "^5.3.19"
  }

My component Navbar.js :我的组件Navbar.js

import React, { Component } from "react";
import { connect } from "react-redux";

class Navbar extends Component {
  render() {
    const { user } = this.props.auth;
    return (
      <div className="navbar-fixed">
        <nav className="z-depth-0">Hello, {user.name} </nav>
      </div>
    );
  }
}
const mapStateToProps = state => ({
  auth: state.auth
});
export default connect(
  mapStateToProps
)(Navbar);

And my story 2-Navbar.stories.js :还有我的故事2-Navbar.stories.js

import React from 'react';
import Provider from '../src/Provider.js'
import configureStore from "../src/configureStore";
import Navbar from '../src/components/layout/Navbar';

export default {
  title: 'Navbar',
  decorators: [storyFn => <Provider store={ configureStore }>{storyFn()}</Provider>]
};

export const Yay = () => <Navbar />;

I want to use "mock" data to pass to my navbar (Like name and avatar url) because otherwise I have redux errors.我想使用“模拟”数据传递到我的导航栏(如名称和头像 url),否则我有 redux 错误。

Appreciate any help.感谢任何帮助。

I had the same problem after upgrade StoryBook.升级 StoryBook 后我遇到了同样的问题。 The workaround that i found was delete node_modules folder, .storyBook folder, delete package-lock.json, and delete any reference to StoryBook in package.json.我找到的解决方法是删除 node_modules 文件夹、.storyBook 文件夹,删除 package-lock.json,并删除 package.json 中对 StoryBook 的任何引用。 After that run "npx sb init" and "npm install".之后运行“npx sb init”和“npm install”。 Then "npm run storybook" and the problem was fixed!然后“npm run storybook”,问题就解决了!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法读取未定义的属性“位置” - Cannot read property 'location' of undefined 带有Webpack错误的React Storybook-模块构建失败:TypeError:无法读取未定义的属性&#39;thisCompilation&#39; - React Storybook with Webpack Error - Module build failed: TypeError: Cannot read property 'thisCompilation' of undefined Storybook 抛出错误:未定义不可迭代(无法读取属性 Symbol(Symbol.iterator)) - Storybook throws error: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) 无法读取未定义的属性“移动”-Vue/Vuetify/Storybook - Cannot read property 'mobile' of undefined - Vue/Vuetify/Storybook 错误为:TypeError:无法读取未定义的属性“位置” - Getting error as :TypeError: Cannot read property 'location' of undefined React-Router 错误“无法读取未定义的属性‘位置’” - React-Router Error "Cannot read property 'location' of undefined" TypeError:使用“窗口”时无法读取未定义反应错误的属性“位置” - TypeError: Cannot read property 'location' of undefined react error on using 'window' 未捕获的TypeError:无法读取未定义的属性“位置” - Uncaught TypeError: Cannot read property 'location' of undefined TypeError:无法读取未定义的属性“位置” - TypeError: Cannot read property 'location' of undefined 无法读取未定义的属性“位置”(useLocation()) - Cannot read property 'location' of undefined (useLocation())
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM