question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react is not defined

See original GitHub issue

Updated to React 16 and Enzyme 3 - using mocha with webpack

import React from 'react';
import Enzyme, { render } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });

describe('...', () => {
  // ...
});

Webpack externals:

  externals: {
    jsdom: 'window',
    'react/addons': true,
    'react/lib/ExecutionEnvironment': true,
    'react/lib/ReactContext': 'window',
    'react-dom/test-utils': true,
    'react-test-renderer/shallow': true,
  },

I get the error ReferenceError: react is not defined

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
ljharbcommented, Oct 3, 2017

Do you have react-test-renderer in your dev deps? Try npm ls - if it returns nonzero then nothing can be expected to work.

0reactions
ljharbcommented, Sep 23, 2020

@trigunam this has nothing to do with enzyme. React’s latest blog post says you need both React 17 and also custom babel configuration to be able to avoid importing React.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught ReferenceError: React is not defined - Stack Overflow
Possible reasons are 1. you didn't load React.JS into your page, 2. you loaded it ...
Read more >
'X' is not defined react/jsx-no-undef Error in React | bobbyhadz
The React.js error "X is not defined react/jsx-no-undef" occurs when we forget to import a function, class or a variable in our code...
Read more >
Getting "Uncaught ReferenceError: react is not defined".
Hi Louie Ambriz, It's hard to tell without seeing your code but it sounds like React is not being loaded into your project....
Read more >
[v4]ReferenceError: React is not defined · Issue #9882 - GitHub
I have submitted PR #9885 to fix this. This is because the jsx-runtime configuration gets removed webpack config during the ejection process ...
Read more >
React is not defined after migrating to React 17 - Meteor forums
Hello, I migrated to React v17. I know that now it is not necessary to import React from 'react'; so I deleted it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found