Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting the error of Window is not defined, after new installation of the node_modules with "youtube-iframe" package #3486

Closed
svenkatesh-nyros opened this issue Jun 19, 2019 · 14 comments · Fixed by #3512
Labels
Analytics Related to analytics

Comments

@svenkatesh-nyros
Copy link

svenkatesh-nyros commented Jun 19, 2019

Describe the bug
After installation of the @aws-amplify with the additional package of youtube-iframe. Getting the error of window is not defined.

Screenshots
Please check the following screenshot of the error. The app is working with previous node_modules without youtube-iframe package inside.

You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app.

2

@svenkatesh-nyros svenkatesh-nyros changed the title Getting the error of Window is defined, after new installation of the node_modules with "youtube-iframe" package Getting the error of Window is undefined, after new installation of the node_modules with "youtube-iframe" package Jun 19, 2019
@mdwt
Copy link

mdwt commented Jun 19, 2019

I also came across that issue after upgrading aws-amplify to 1.1.29.

A workaround I'm using to get around it (I'm using amplify from Node backend) is to add the following polyfill before importing Amplify...this fixes that error but opens up some other issues involving AWS Pinpoint down the line..

const ws = require('ws');
(global as any).WebSocket = ws;
(global as any).window = (global as any).window || {
    setTimeout: setTimeout,
    clearTimeout: clearTimeout,
    WebSocket: ws,
    ArrayBuffer: global.ArrayBuffer,
    addEventListener: function () {
    },
    navigator: {onLine: true}
};
(global as any).localStorage = {
    store: {},
    getItem: function (key) {
        return this.store[key];
    },
    setItem: function (key, value) {
        this.store[key] = value;
    },
    removeItem: function (key) {
        delete this.store[key];
    }
};

@sammartinez
Copy link
Contributor

@svenkatesh-nyros We did have an issue with the youtube-iframe npm package in the aws-analytics package yesterday that we ended up doing an unstable publish yesterday afternoon to fix. Please update to the unstable version and report back

@GeorgeBellTMH
Copy link

This resolved the issue, but now I am getting:

node -r esm ssr-server.js

/Users/georgebell/Desktop/Code/tmh-web/web/node_modules/@aws-amplify/ui/dist/aws-amplify-ui.js:1
ReferenceError: window is not defined
at Object. (/Users/georgebell/Desktop/Code/tmh-web/web/node_modules/@aws-amplify/ui/dist/aws-amplify-ui.js:1)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)

@svenkatesh-nyros svenkatesh-nyros changed the title Getting the error of Window is undefined, after new installation of the node_modules with "youtube-iframe" package Getting the error of Window is not defined, after new installation of the node_modules with "youtube-iframe" package Jun 20, 2019
@svenkatesh-nyros
Copy link
Author

@svenkatesh-nyros We did have an issue with the youtube-iframe npm package in the aws-analytics package yesterday that we ended up doing an unstable publish yesterday afternoon to fix. Please update to the unstable version and report back

@sammartinez .
I installed the "aws-amplify": "1.1.30-unstable.0" latest unstable version and checked the app. Now I am getting the following error.

ReferenceError: window is not defined
in the folder node_modules/@aws-amplify/ui/dist/aws-amplify-ui.js

Please check the following screenshot.

3-aws-git-error

@artista7
Copy link

I thought I'm getting something wrong. But seems like this is one of the latest issues. Please get this fixed asap. I am using aws-amplify in lambda and the following error is coming :-
{
"errorType": "ReferenceError",
"errorMessage": "window is not defined",
"trace": [
"ReferenceError: window is not defined",
" at Object. (/var/task/node_modules/youtube-iframe/index.js:50:3)",
" at Module._compile (internal/modules/cjs/loader.js:701:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)",
" at Module.load (internal/modules/cjs/loader.js:600:32)",
" at tryModuleLoad (internal/modules/cjs/loader.js:539:12)",
" at Function.Module._load (internal/modules/cjs/loader.js:531:3)",
" at Module.require (internal/modules/cjs/loader.js:637:17)",
" at require (internal/modules/cjs/helpers.js:22:18)",
" at Object. (/var/task/node_modules/@aws-amplify/analytics/lib/Providers/AmazonPersonalizeHelper/MediaAutoTrack.js:15:27)",
" at Module._compile (internal/modules/cjs/loader.js:701:30)"
]

@kim-ra
Copy link

kim-ra commented Jun 20, 2019

Facing the same issue just getting started out with Amplify, does anyone happen to know workable versions to roll back to in the meantime to unblock?

@artista7
Copy link

Hey, meanwhile the error might be getting fixed, you can use individual amplify components in your app and use them like :-

const Amplify = require('@aws-amplify/core').default;
var API = require('@aws-amplify/api').default;
var { graphqlOperation } = require('@aws-amplify/api');
var Auth = require('@aws-amplify/auth').default;

@patrickcze
Copy link

Also having the same issue on a node app we are running on server only. Using the current unstable branch 1.1.30-unstable.0 is causing the following error which still seems related.

ReferenceError: window is not defined
    at Object.<anonymous> (/home/ec2-user/viva-api/node_modules/@aws-amplify/ui/dist/aws-amplify-ui.js:1:289)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/ec2-user/viva-api/node_modules/aws-amplify/lib/index.js:39:10)

@aldegoeij
Copy link

same here 1.1.30-unstable.1 also still giving window not defined for amplify-ui

@anarerdene
Copy link

Same. window is not defined node_modules/@aws-amplify/ui/dist/aws-amplify-ui.js:1:289.

how i fix this rly quick ?

@buithaibinh
Copy link

buithaibinh commented Jul 11, 2019

@anarerdene
If you not use @aws-amplify/ui module then you can remove this module.
I already did it and it work

I only add modules which i will use.
Example:

import Auth from '@aws-amplify/auth'
import Storage from '@aws-amplify/storage'
import API from '@aws-amplify/api'
import Analytics from '@aws-amplify/analytics'

@mkondel
Copy link

mkondel commented Jul 15, 2019

Here is an alternative quick fix, I only had to add 'resolutions' to my package.json. This is the source: #3477

  "resolutions": {
    "@aws-amplify/ui": "1.0.19"
  },

@aldegoeij
Copy link

referencing tickets #3486, #3506, #3615, #3015, #876, #3477 and webpack/webpack#6522

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Analytics Related to analytics
Projects
None yet
Development

Successfully merging a pull request may close this issue.