Javascript ReactJS Webpack错误类型。toUpperCase不是函数

Javascript ReactJS Webpack错误类型。toUpperCase不是函数,javascript,reactjs,webpack,Javascript,Reactjs,Webpack,因此,我使用webpack将react组件捆绑到myApp.js中。我在webpack.config.js文件中创建了一个名为MyApp的全局公开变量,该变量保存了其中的所有react组件,如下所示: entry: { // create myApp.js, expose MyApp global object // index.js lists all my react components to include in myApp.js 'myApp.js': 'expos

因此,我使用webpack将react组件捆绑到myApp.js中。我在webpack.config.js文件中创建了一个名为MyApp的全局公开变量,该变量保存了其中的所有react组件,如下所示:

entry: {
// create myApp.js, expose MyApp global object  
// index.js lists all my react components to include in myApp.js
        'myApp.js': 'expose?MyApp!../ReactComponents/index.js'
    },
现在在javascript中,当我使用以下语法呈现react组件时,我得到了错误类型。toUpperCase不是一个函数:

// MyApp.Employees - MyApp is the global object 
// and Employees is my react component within MyApp global object

    window.onload = function () {
// type is object and not null
// so it is found
alert(MyApp.Employees); 

// react will not render it though
// using this syntax
        React.render(React.createElement(MyApp.Employees, null), document.getElementById('react'));
    }
我一直得到错误类型。toUpperCase不是一个函数

让react呈现MyApp.Employees的语法是什么

或者是什么原因导致出现此错误


谢谢你的建议

似乎您已经有了React创建的
Employees
组件,并且您正试图在该组件上使用
createElement

试一试

var Employees=MyApp.Employees;
React.render(,document.getElementById('React');

似乎您已经有了React创建的
员工
组件,并且您正试图在该组件上使用
createElement

试一试

var Employees=MyApp.Employees;
React.render(,document.getElementById('React');
尝试使用

String.prototype.toLocaleUpperCase.call('your string'); 

试用

String.prototype.toLocaleUpperCase.call('your string'); 


感谢您的回复,但不幸的是,它没有起作用。Employees组件尚未创建,它刚刚被webpack捆绑到一个.js文件中。我试图使用blobal变量MyApp将其从网页包中取出,然后创建它。因此,它就在我的.js文件中要创建/使用,但尚未创建。这是我的webpack.js文件中我的员工组件的开始。。。var Employees=React.createClass({displayName:“Employees”,……为什么首先需要公开?您可以在React组件模块中编写
module.exports
,然后在需要的地方导入它,如下所示:
var Employees=React.createClass(…);module.exports=Employees;
然后
从./Components/Employees
导入员工,并像
React.render(,…)一样使用它
是的,如果您使用react语法在react组件中执行此操作,那么您是正确的。但是我使用纯javascript将react组件呈现到div中,并使用webpack将react组件捆绑到一个.js文件中,使用自己的方法绑定组件以及如何访问它们。如果您没有绑定使用webpack开发react组件并渲染它们,那么我所解释的不适用于该场景,这可能是我的情况看起来很奇怪的原因。感谢您的响应,但不幸的是它没有工作。Employees组件尚未创建,我们刚刚将其捆绑到一个.js文件中bpack。我正试图使用blobal变量MyApp将其从网页包中取出,然后创建它。因此,它位于要创建/使用的.js文件中,但尚未创建。以下是我的webpack.js文件中my Employees组件的开始…var Employees=React.createClass({displayName:“Employees”,…为什么首先需要公开?您可以在React组件模块中编写
module.exports
,然后在需要的地方导入,如下所示:
var Employees=React.createClass(…);module.exports=Employees;
然后
从./Components/Employees
导入员工,并像
React.render(,…)一样使用它
是的,如果您使用react语法在react组件中执行此操作,那么您是正确的。但是我使用纯javascript将react组件呈现到div中,并使用webpack将react组件捆绑到一个.js文件中,使用自己的方法绑定组件以及如何访问它们。如果您没有绑定使用webpack开发react组件并渲染它们,那么我所解释的不适用于该场景,这可能是我的情况看起来很奇怪的原因。
String.prototype.toUpperCase.call('your string');