fetch-intercept icon indicating copy to clipboard operation
fetch-intercept copied to clipboard

No fetch avaibale. Unable to register fetch-intercept

Open alexey2baranov opened this issue 5 years ago • 1 comments

in Jest test

import fetch from 'node-fetch'
global.fetch= fetch
import fetchIntercept from "fetch-intercept";

throws

● Test suite failed to run

No fetch avaibale. Unable to register fetch-intercept

  10 | 
  11 | // fetchIntercept.register(errorInterceptor)
> 12 | // fetchIntercept.register(dataInterceptor)
     |                                              ^
  13 | // fetchIntercept.register(cookieInterceptor)
  14 | // fetchIntercept.register(headersInterceptor)
  15 | 

  at attach (node_modules/fetch-intercept/lib/webpack:/src/attach.js?1269:38:13)
  at Object.<anonymous> (node_modules/fetch-intercept/lib/webpack:/src/node.js:3:18)
  at Object.<anonymous> (node_modules/fetch-intercept/lib/node.js:53:31)
  at __webpack_require__ (node_modules/fetch-intercept/lib/webpack:/webpack/bootstrap 288f28a76d94cd56de0b?2753:19:1)
  at node_modules/fetch-intercept/lib/webpack:/webpack/bootstrap 288f28a76d94cd56de0b?2753:39:1
  at Object.<anonymous> (node_modules/fetch-intercept/lib/node.js:44:10)
  at Object.<anonymous> (src/api/index.js:12:46)
  at Object.<anonymous> (src/plugins/bottle.js:24:35)
  at Object.<anonymous> (src/models/AbstractSync.js:25:15)
  at Object.<anonymous> (src/models/index.js:27:44)
  at Object.<anonymous> (src/plugins/className.js:5:38)
  at Object.<anonymous> (tests/test-setup.js:30:1)

alexey2baranov avatar Jan 07 '20 20:01 alexey2baranov

While running in node environment, fetch-intercept uses whatwg-fetch pollyfill but since it is not included in dependencies, it is not available and hence generates this error.

https://github.com/werk85/fetch-intercept/blob/develop/src/attach.js#L36

As a workaround, adding [email protected] as a dev dependency in the main project worked for me.

Shishir-Tiwari avatar Aug 14 '20 08:08 Shishir-Tiwari