React JSX 文件出现错误“无法读取未定义的属性 'createElement'”
2022-08-30 04:22:46
我有一个正在运行的文件test_stuff.jsnpm test
它几乎看起来像这样:
import { assert } from 'assert';
import { MyProvider } from '../src/index';
import { React } from 'react';
const myProvider = (
<MyProvider>
</MyProvider>
);
describe('Array', function() {
describe('#indexOf()', function() {
it('should return -1 when the value is not present', function() {
assert.equal(-1, [1,2,3].indexOf(4));
});
});
});
不幸的是,我收到错误
/Users/me/projects/myproj/test/test_stuff.js:11
var myProvider = _react.React.createElement(_index.MyProvider, null);
^
TypeError: Cannot read property 'createElement' of undefined
at Object.<anonymous> (/Users/me/projects/myproj/test/test_stuff.js:7:7)
那是什么意思?我正在成功地从'react'导入React,那么为什么React是未定义的呢?这是_react。React,无论这意味着什么...