Module not found: Error: Cannot resolve module 'whatwg-fetch' when building with webpack
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
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?
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 .
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?
FWIW I had this same issue, and installed whatwg-fetch and everything worked out great! Thanks!
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
just comment
module.exports = require("whatwg-fetch");
line in browser.js file in fetch-intercept/lib folder
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.