js-data-http icon indicating copy to clipboard operation
js-data-http copied to clipboard

Error with window on Universal Rendering

Open Gregcop1 opened this issue 9 years ago • 3 comments

I'm trying to use js-data-http with universal rendering but I got an error about window's existence

FAILED: window is not defined ReferenceError: window is not defined
at Object.<anonymous> (xxxxx/node_modules/js-data-http/dist/webpack:/~/axios/lib/adapters/xhr.js:16:1)
at __webpack_require__ (xxxxx/node_modules/js-data-http/dist/js-data-http.js:38:30)
at executor (xxxxx/node_modules/js-data-http/dist/webpack:/~/axios/lib/core/dispatchRequest.js:31:1)
at dispatchRequest (xxxxx/node_modules/js-data-http/dist/webpack:/~/axios/lib/core/dispatchRequest.js:19:1)
at process._tickCallback (internal/process/next_tick.js:103:7)
(node:25772) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): ReferenceError: window is not defined

Regarding this code

	      if (typeof config.adapter === 'function') {
	        // For custom adapter support
	        adapter = config.adapter;
	      } else if (typeof XMLHttpRequest !== 'undefined') {
	        // For browsers use XHR adapter
	        adapter = __webpack_require__(8);
	      } else if (typeof process !== 'undefined') {
	        // For node use HTTP adapter
	        adapter = __webpack_require__(8);
	      }

it require the same function for browser or node but in this function, window object is used without checking its existance.

BTW, thanks a lot for js-data and those adapter...your job is quite impressive

Gregcop1 avatar Nov 25 '16 14:11 Gregcop1

My Bad it seems to be a problem in axios adapter

Gregcop1 avatar Nov 25 '16 15:11 Gregcop1

Hi again. I posted the issue on axios repo and I got this answer. Do you know a way to help me please ? https://github.com/mzabriskie/axios/issues/556

Gregcop1 avatar Nov 27 '16 21:11 Gregcop1

On the server, you should use the js-data-http-node NPM package instead of js-data-http.

jmdobry avatar Dec 12 '16 03:12 jmdobry