Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jeffcharles opened this issue Aug 23, 2016 · 7 comments
Assignees

Comments

@jeffcharles
Copy link

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
@mlegenhausen
Copy link
Owner

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 mlegenhausen self-assigned this Aug 24, 2016
@jeffcharles
Copy link
Author

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
#6 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJdCjLNON-d7Kohz3Z1mcYLKt47gOZRks5qi_SMgaJpZM4JrNS4
.

@mlegenhausen
Copy link
Owner

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?

@bmcgary
Copy link

bmcgary commented Apr 14, 2017

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

@surfjedi
Copy link

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

@mmesar
Copy link

mmesar commented Jan 1, 2019

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

@lougreenwood
Copy link

lougreenwood commented May 29, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants