user3403614 user3403614 - 1 year ago 275
React JSX Question

How to fix error 'FB' is not defined no-undef on create-react-app project?

I made the project using this link as my starting file.

But after i tried to make Facebook login button with follow by their official docs with this.

console.log('login mount');
window.fbAsyncInit = function() {
appId : '320866754951228',
xfbml : true,
version : 'v2.6'

FB.getLoginStatus(function(response) {


(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); = id;
js.src = "//";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

So i got this errors when the browser was refreshed.

Failed to compile.

Error in ./src/components/user_profile/LoginForm.js

70:13 error 'FB' is not defined no-undef
76:13 error 'FB' is not defined no-undef

✖ 2 problems (2 errors, 0 warnings)

So i guess because ESLint that cause this errors.
How can i fix this or make the exception for this


Answer Source

ESLint doesn't know that the variable FB is a global. You can declare a variable you referenced as a global by adding the following to the top of your file:

/*global FB*/

For more information, check out the "Rule Details" section on the official ESLint docs:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download