require('react') vs require('React')

Viewed 76

The following code in external node_modules is not working:

var _react = require('react');

But:

var _react = require('React');

works. Now I have a problem that in some node_modules it is required with 'react', and then I get this error:

Uncaught Error: Cannot find module 'react'

I am using gulp as build tool.

What can I do so that both requires will work?

2 Answers

Do you have 'React' added in your package.json ?

If not, add: "react": "17.0.2" (or another React version)

Try running the command:

npm install 

And try again

Require is not a React api. Try this syntax:

import React from 'react'
Related