indexeddbshim / IndexedDBShim

A polyfill for IndexedDB using WebSql
Other
968 stars 191 forks source link

Browser error - Cannot assign to read only property 'window' of object '#<Window>' #332

Open Shooshte opened 6 years ago

Shooshte commented 6 years ago

I am trying to use IndexedDbShim with a react application. I am using create-react-app and this is the main app index.js file that runs before everything else:

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

I am getting the following error in the console:

Uncaught TypeError: Cannot assign to read only property 'window' of object '#' at Object. (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

Is there a known workaround for this? Or is there a polyfill version that ships as a single file that I can use as a static dependencies (webpack bundles my node_modules code so I cannot just include the npm install in my static html files).

Thanks for the help.