Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  53] [ 4]  / answers: 1 / hits: 117430  / 8 Years ago, sat, september 10, 2016, 12:00:00

I have a file test_stuff.js that I am running with npm test



It pretty much looks like this:



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));
});
});
});


Unfortunately, I get the error



/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)


What does that mean? I am importing React from 'react' successfully, so why would React be undefined? It is _react.React, whatever that means...


More From » npm

 Answers
4

To import React do import React from 'react' You add brackets when the thing you are importing is not the default export in that module or file. In case of react, it's the default export.



This might apply to your other imports depending on how you defined them.


[#60756] Wednesday, September 7, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
coleman

Total Points: 518
Total Questions: 81
Total Answers: 96

Location: Aland Islands
Member since Wed, Nov 17, 2021
3 Years ago
;