将发布的js库发布为具有axios依赖项的npm包会导致TypeError:无法读取未定义的属性“ dispose”

时间:2019-03-29 06:48:49

标签: javascript reactjs npm axios

我正在尝试发布具有依赖关系的reactjs npm软件包作为axios。 我的目的是在npm包中获取数据并将其显示在dom上。

但是在react项目上使用它会给我以下错误

Uncaught (in promise) TypeError: Cannot read property 'dispose' of undefined
    at Object../node_modules/react-dev-utils/webpackHotDevClient.js (webpackHotDevClient.js:45)
....
Uncaught Error: Iframe has not been created yet.
    at me (index.js:2087)
    at Object.window.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__.iframeReady (index.js:2097)
......

我的lib代码在https://github.com/e06widu/create-react-library-e06widu上, 在https://www.npmjs.com/package/create-react-library-e06widu

上发布的库

在package.json中,我如下添加了peerDependencies

"dependencies": {},
  "peerDependencies": {
    "axios": "^0.18.0",
    "react": "^16.8.1",
    "react-dom": "^16.8.1"
  },

这就是我在项目中使用它的方式

    import {
      Example,
      SecondExample,
      DashBoard,
      Greeting
    } from 'create-react-library-e06widu';

    ........

      handleLoginClick = () => {
        console.log('Handle login click');
      }

      render() {

        const greeting = "From lib e06widu"
        return (
          <div>
            <p>Login</p>
            <button className="btn btn-primary" onClick={this.handleLoginClick}>Login</button>

            <h1>My React Component</h1>
            <Greeting greeting={greeting} login={this.handleLoginClick}/>
            <Example/>
            <SecondExample/>

          </div>
        )
      }

...

0 个答案:

没有答案