How to add global variable if not defined

To avoid rewriting a lot of d3 code in a project, I’m trying to use an older version of d3 (3.5.5). I get this error in the console, which I assume has to do with javascript module system changing over the years. Is there a way to still use an older version of d3 by defining global somewhere in a react project?

index.js:4  Uncaught ReferenceError: global is not defined
    at node_modules/d3/index.js (index.js:4:13)
    at __require (chunk-LNEMQRCO.js?v=b28db8c8:9:50)
    at index.js:9:65

This is what it says it node_modules/d3/index.js (index.js:4:13)

var globals = {};

// Stash old global.
if ("d3" in global) globals.d3 = global.d3;

module.exports = require("./d3");

// Restore old global.
if ("d3" in globals) global.d3 = globals.d3; else delete global.d3;