【问题标题】:React, Material UI, JSPM and Babel : Error: Can't add property context, object is not extensibleReact、Material UI、JSPM 和 Babel:错误:无法添加属性上下文,对象不可扩展
【发布时间】:2015-08-23 21:43:23
【问题描述】:

我正在尝试通过 Babel 使用 JSPM 和 ES6 为 React 设置 Material UI。

1) 使用jspm install material-ui=npm:material-ui安装material-ui

2) 这使我能够将材料 ui 导入到我的 React 组件文件中,如下所示:import {TextField, LeftNav} from 'material-ui'

此时我在我的 ES6 文件中得到了正确的引用,所以如果我做一个 console.log(TextField); 我打印了反应组件。

遗憾的是,我当前的问题是尝试在 jsx 中使用该组件时遇到错误

   return (
     <div>
       <TextField />
     </div>
   ) 

抛出错误:

Warning: getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.
warning.js:17 Warning: Something is calling a React component directly. Use a factory or JSX instead. See: http://fb.me/react-legacyfactory
warning.js:26 Warning: TextField(...): No `render` method found on the returned component instance: you may have forgotten to define `render` in your component or you may have accidentally tried to render an element whose type is a function that isn't a React component.
warning.js:17 Warning: Don't set the props property of the component. Mutate the existing props object instead.
dashboard:1 Uncaught (in promise) Error: Can't add property context, object is not extensible
    Error loading http://localhost:3000/app.js
    at ReactCompositeComponentMixin.mountComponent 

基于警告,我认为该错误可能是由工具组合 Babel+JSPM+Material-UI 创建的特定情况引起的。

【问题讨论】:

    标签: reactjs babeljs jspm material-ui


    【解决方案1】:

    检查您正在运行的 react 版本。它应该是 v0.13.3。 更多信息可以在这里找到:https://github.com/callemall/material-ui/issues/1303

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-21
      • 2021-02-02
      • 1970-01-01
      • 2020-11-15
      • 2019-02-28
      • 2019-08-29
      • 2021-10-13
      • 1970-01-01
      相关资源
      最近更新 更多