Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

ReferenceError: window is not defined #45

Open
exabugs opened this issue Feb 1, 2017 · 5 comments
Open

ReferenceError: window is not defined #45

exabugs opened this issue Feb 1, 2017 · 5 comments

Comments

@exabugs
Copy link

exabugs commented Feb 1, 2017

On plain JS (not Browser) environment (ex. unit test), CognitoSyncManager don't work properly.

ReferenceError: window is not defined
    at new a (src/_lib/amazon-cognito.min.js:35:23975)
    at new a (src/_lib/amazon-cognito.min.js:35:13090)
    at new AWS.CognitoSyncManager (src/_lib/amazon-cognito.min.js:35:377)
    at server/server_test.js:43:28
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickDomainCallback (internal/process/next_tick.js:122:9)

code is below.

      aws.config.credentials.get(() => {
        const syncClient = new aws.CognitoSyncManager();
        syncClient.openOrCreateDataset('myDataset', (err, dataset) => {
          dataset.put('myKey', 'myValue', (err, record) => {
            dataset.synchronize({
              onSuccess: (data, newRecords) => {
                // Your handler code here
                console.log();
              }
            });
          });
        });
      });
@johnborges
Copy link

What JS environment are you using? In nodeJS there is no window object.

@exabugs
Copy link
Author

exabugs commented Feb 2, 2017

Yes, I use this on Nodejs6.9 + Mocha at UnitTest environment.
Production environment is on the modern browser, Babel + Webpack compiled JS.

Test with browser is too difficult, so I'd like to test it on simple environment.

This library is wrapper HTML5 WebStorage and only use on Browser, isn't it ?

@itrestian
Copy link
Contributor

Yes, it uses window local storage for storing data. That wouldn't be available in node.

@oieesah
Copy link

oieesah commented Feb 20, 2017

So what can be used instead of window? Can we make it work with node?

@itrestian
Copy link
Contributor

You could use a package that substitutes that in node such as node-localstorage. However, we have only tested this library in a browser environment.

https://www.npmjs.com/package/node-localstorage

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants