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

Module not found: Error: Cannot resolve module 'whatwg-fetch' when building with webpack

Open jeffcharles opened this issue 9 years ago • 7 comments

I'm trying to use this as part of a webpack-based web UI. I installed it with npm install --save-dev fetch-intercept. My code looks like:

import fetchIntercept from 'fetch-intercept';

fetchIntercept.register({
  request: (url, config) => [url, config],
  requestError: err => Promise.reject(err),
  response: res => res,
  responseError: err => Promise.reject(err)
});

in authFetchIntercept.js and I have import './authFetchIntercept.js' inside my javascript's entrypoint. Trying to build the site with webpack results in:

ERROR in ./~/fetch-intercept/lib/index.js
Module not found: Error: Cannot resolve module 'whatwg-fetch' in /Users/jeffreycharles/projects/facial-recognition-webui/node_modules/fetch-intercept/lib
 @ ./~/fetch-intercept/lib/index.js 261:18-41

jeffcharles avatar Aug 23 '16 17:08 jeffcharles

It should be solved when you install whatwg-fetch or define whatwg-fetch as external. The intention is to automatically resolve some fetch implementation, that can be intercepted.

Never tested fetch-intercept without providing a polyfill for legecy browsers. Which platform are you targeting?

mlegenhausen avatar Aug 24 '16 07:08 mlegenhausen

Latest Chrome which has a native fetch implementation. The app is a prototype purely for internal use so no need for legacy or cross-browser support.

On Wed, Aug 24, 2016, 03:36 Malte Legenhausen [email protected] wrote:

It should be solved when you install whatwg-fetch or define whatwg-fetch as external. The intention is to automatically resolve some fetch implementation, that can be intercepted.

Never tested fetch-intercept without providing a polyfill for legecy browsers. Which platform are you targeting?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/werk85/fetch-intercept/issues/6#issuecomment-241981702, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJdCjLNON-d7Kohz3Z1mcYLKt47gOZRks5qi_SMgaJpZM4JrNS4 .

jeffcharles avatar Aug 24 '16 12:08 jeffcharles

Ok I think requiring whatwg-fetch is not the best way to ensure this. I think instead a simple error should be thrown during runtime and the developer needs to make sure that a fetch api is available in all of his environments.

For now it is possible for you to install whatwg-fetch?

mlegenhausen avatar Aug 24 '16 13:08 mlegenhausen

FWIW I had this same issue, and installed whatwg-fetch and everything worked out great! Thanks!

bmcgary avatar Apr 14 '17 15:04 bmcgary

I am having same issues. And even installing Whatwg-fetch, then need es6-promise-promise.. would be great if these weren't necessary as babel, and ES6 are much more widely supported

surfjedi avatar Jun 27 '17 21:06 surfjedi

just comment module.exports = require("whatwg-fetch"); line in browser.js file in fetch-intercept/lib folder

mmesar avatar Jan 01 '19 23:01 mmesar

IMO, any upstream fix should probably also account for node-only environments where node-fetch is used.

My use case for this project is to intercept & re-write Origin readers when I pre-render pages on my CI (CI would fail CORS because of bad Origin header).

Adding whatwg-fetch as a dependency isn't ideal since I use native fetch or a polyfill on the client side (via ember-fetch) and node-fetch on server-side. So whatwg-fetch is a useless dep for me.

lougreenwood avatar May 29 '19 06:05 lougreenwood