Skip to content

window is not defined #65

@ksntcrq

Description

@ksntcrq

Hey,

When using server-side rendering, and import ReactFilestack from 'filestack-react';, I run into the following problem:

ReferenceError: window is not defined
    at Object. (/data/www/studocu/node_modules/filestack-react/dist/webpack:/webpack/universalModuleDefinition:8:1)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Module._compile (/data/www/studocu/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Object.newLoader [as .js] (/data/www/studocu/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Function._load (/usr/local/share/.config/yarn/global/node_modules/@pm2/io/src/metrics/httpMetrics.ts:190:35)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object. (/data/www/studocu/resources/assets/redux/studocu/components/DropArea.jsx:7:1)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Module._compile (/data/www/studocu/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Object.newLoader [as .jsx] (/data/www/studocu/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Function._load (/usr/local/share/.config/yarn/global/node_modules/@pm2/io/src/metrics/httpMetrics.ts:190:35)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object. (/data/www/studocu/resources/assets/redux/studocu/components/lists/DropAreaList.jsx:8:1)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Module._compile (/data/www/studocu/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Object.newLoader [as .jsx] (/data/www/studocu/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Function._load (/usr/local/share/.config/yarn/global/node_modules/@pm2/io/src/metrics/httpMetrics.ts:190:35)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object. (/data/www/studocu/resources/assets/redux/studocu/pages/Upload.jsx:33:1)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Module._compile (/data/www/studocu/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Object.newLoader [as .jsx] (/data/www/studocu/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Function._load (/usr/local/share/.config/yarn/global/node_modules/@pm2/io/src/metrics/httpMetrics.ts:190:35)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at handleRender (/data/www/studocu/server.js:202:20)
    at Layer.handle [as handle_request] (/data/www/studocu/node_modules/express/lib/router/layer.js:95:5)
    at next (/data/www/studocu/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/data/www/studocu/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/data/www/studocu/node_modules/express/lib/router/layer.js:95:5)
    at /data/www/studocu/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/data/www/studocu/node_modules/express/lib/router/index.js:335:12)
    at next (/data/www/studocu/node_modules/express/lib/router/index.js:275:10)
    at /data/www/studocu/node_modules/body-parser/lib/read.js:130:5
    at invokeCallback (/data/www/studocu/node_modules/raw-body/index.js:224:16)
    at done (/data/www/studocu/node_modules/raw-body/index.js:213:7)
    at IncomingMessage.onEnd (/data/www/studocu/node_modules/raw-body/index.js:273:7)
    at IncomingMessage.emit (events.js:201:15)
    at IncomingMessage.EventEmitter.emit (domain.js:471:20)
    at endReadableNT (_stream_readable.js:1130:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:9)

So I have to conditionally import the component, which is not really convenient:

let ReactFilestack;
if (typeof window !== 'undefined' && window !== null) {
    ReactFilestack = require('filestack-react').default;
}

Because of that I also have a mismatch between server and client sides, as the button is not rendered on the server side but is on the client side.

The filestack-react version I use is 2.0.6.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions