react-facebook icon indicating copy to clipboard operation
react-facebook copied to clipboard

[Gatsby] React is not defined

Open winstonma opened this issue 3 years ago • 8 comments
trafficstars

I was using react-facebook v8.14.0 on my Gatsby site and updated to v.9.0.5 recently. After the update I tried to build my site again and I saw the following error message.

WebpackError: ReferenceError: React is not defined

Not sure how to fix the problem and would like to see if other people saw this message.

winstonma avatar Aug 30 '22 14:08 winstonma

Please try to use latest version. I enabled legacy output and it should work fine now

seeden avatar Aug 30 '22 19:08 seeden

Hi @seeden,

Just tried v9.0.7 and I still got the error message while building my Gatsby project.

  WebpackError: ReferenceError: React is not defined

  - index.js:1 
    [.]/[react-facebook]/dist/esm/index.js:1:4045

Do you know how could I solve this problem? Thanks a lot

winstonma avatar Aug 30 '22 22:08 winstonma

Same issue with using a CRA app. There was a change in FaceBookProvider.tsx to remove React from imports, could this be the issue?

import React, { useState, useEffect, type ReactNode } from 'react'; to import { useState, useEffect, type ReactNode } from 'react';

Linting is showing an error as well. "'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.ts"

davidcheal avatar Aug 31 '22 04:08 davidcheal

It is related to https://github.com/egoist/tsup/issues/579. I will switch to rollup. Sorry for delay

seeden avatar Aug 31 '22 21:08 seeden

I'm getting the same error in a Vite project.

toburger avatar Sep 17 '22 10:09 toburger

I am getting the same error in react nextjs project? Any solutions.

siamahnaf avatar Sep 23 '22 11:09 siamahnaf

Can you try latest version?

seeden avatar Sep 28 '22 12:09 seeden

@seeden I tried v9.0.8 and it fixes the build problem.

winstonma avatar Oct 04 '22 11:10 winstonma