pixolith / fabricjs-customise-controls-extension

Customise the Icon/Cursor/Action of the fabric.js controls
275 stars 100 forks source link

ReferenceError: window is not defined #64

Closed nogurenn closed 6 years ago

nogurenn commented 6 years ago

I've checked React Starter Kit for information regarding this and it appears I need fabric-customise-controls to render client-side only. However, how can I do this? Is there a way to support server-side rendering?

Relevant dependencies

"node": ">=5.0 <7",
"npm": ">=3.3 <4"
"webpack": "^1.13.1",
"webpack-hot-middleware": "^2.16.1",
"webpack-middleware": "^1.5.1",
/somPath/node_modules/fabric-customise-controls/dist/customiseControls.js:713
})(window);
   ^
ReferenceError: window is not defined
    at Object.<anonymous> (/somePath/node_modules/fabric-customise-controls/dist/customiseControls.js:713:4)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.module.exports.Object.defineProperty.value (/somePath/build/webpack:/external "fabric-customise-controls":1:1)
    at __webpack_require__ (/somePath/build/webpack:/webpack/bootstrap 9ae600d83e30eed8ae9a:19:1)
    at Object.<anonymous> (/somePath/build/webpack:/components/DesignApp/DesignApp.js:12:1)
    at __webpack_require__ (/somePath/build/webpack:/webpack/bootstrap 9ae600d83e30eed8ae9a:19:1)
    at Object.<anonymous> (/somePath/build/webpack:/components/AddProduct/AddProduct.js:23:1)
    at __webpack_require__ (/somePath/build/webpack:/webpack/bootstrap 9ae600d83e30eed8ae9a:19:1)
    at Object.module.exports.Object.defineProperty.value (/somePath/build/webpack:/routes/Shops/AddProduct/index.js:2:1)
    at __webpack_require__ (/somePath/build/webpack:/webpack/bootstrap 9ae600d83e30eed8ae9a:19:1)
/somePath/tools/runServer.js:71
        throw new Error(`Server terminated unexpectedly with code: ${code} signal: ${signal}`);
        ^

Error: Server terminated unexpectedly with code: 1 signal: null
    at ChildProcess.server.once (/somePath/tools/runServer.js:53:15)
    at ChildProcess.g (events.js:292:16)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12
MDSLKTR commented 6 years ago

Hey there. I could make this opt out of server side rendering when window is not defined however it doesn't make much sense. In these Server Side Rendering packages there usually are two different entrypoints. You should look for something called client.js in contrast to server.js. In the client.js you import this package using es6 import right after fabric.js.

nasiruddin-saiyed commented 5 years ago

Though its a closed issue but it may going to help someone who is trying to resolve this error while SSR,

i'm trying get it work in react with SSR so basically problem is, window is not available on server renderer, so better to not to import on component

import "fabric-customise-controls"; - THIS WILL NOT WORK

componentDidMount() { require('fabric-customise-controls'); // **THIS IS WORKING UNDER SSR** }