我试图使用IndexedDbShim与反应应用程序 . 我正在使用create-react-app,这是在其他所有内容之前运行的主应用程序 index.js

import '@babel/polyfill';

import React from 'react';
import ReactDOM from 'react-dom';
import { toJS } from 'mobx';
import AsyncLoad from './common/components/AsyncComponent';

import { setGlobalVars } from 'indexeddbshim';

global.window = global; // We'll allow ourselves to use `window.indexedDB` or `indexedDB` as a global
setGlobalVars(); // See signature below
...
// unrelated code continues here

我在控制台中收到以下错误:

未捕获的TypeError:无法分配给Object的对象'#'的只读属性'window' . (index.js:10)at Object ../ src / index.js(index.js:35)at webpack_require(bootstrap 8babaf20081f9cc7653e:698)at fn(bootstrap 8babaf20081f9cc7653e:111)at Object.0(index.js:35) )at webpack_require(bootstrap 8babaf20081f9cc7653e:698)at bootstrap 8babaf20081f9cc7653e:796 at bootstrap 8babaf20081f9cc7653e:796

是否有使用webpack设置全局窗口变量(IndexedDBShim似乎需要它)的已知解决方法?使用浏览器控制台进行设置似乎按预期工作 .