Code Monkey home page Code Monkey logo

Comments (3)

lquixada avatar lquixada commented on May 22, 2024 1

Hi folks! Thanks for the reported issues. Just like node, whenever a bundler finds an import/require statement, it's going to check the module's package.json to look for the entry point.

Here's how each resolver behaves:

  • node: looks for the main property by default.
  • webpack: looks for the browser, then the module and then the main properties by default. Customizable via resolve.mainFields option in the webpack.config.js file.
  • rollup: looks for the main property by default. Customizable via rollup-plugin-node-resolve plugin.
  • metro (React Native's packager): looks for the react-native, then the browser and then the main properties by default. See code.

And here's how cross-fetch's package.json is configured:

  • "main": "dist/node-ponyfill.js" (for node)
  • "browser": "dist/browser-ponyfill.js" (for webpack)
  • "react-native": "dist/react-native-ponyfill.js" (for metro)

So whether you're using webpack or rollup, you probably need to configure them to resolve the same fields as React Native's metro.

from cross-fetch.

lquixada avatar lquixada commented on May 22, 2024

node-fetch shouldn't be loaded in RN environment. cross-fetch uses a specific entry-point for React Native that proxies to the fetch provided by the environment.

maybe your bundler is resolving the wrong entry point: "main" instead of "react-native" (see package.json).

from cross-fetch.

evaneus avatar evaneus commented on May 22, 2024

I'm having a similar issue, a default rollup build will include node-fetch in browser build when using cross-fetch. Tried this with graphql-request and apollo-fetch.

Not sure if anything can be done in this lib to make it rollup-friendly or if it's something that must be handled on the rollup side.

I reproduced basic example here, just took the default rollup starter app and added graphql-request lib:

https://github.com/evaneus/rollup-starter-app

this ends up with require calls (for node-fetch) being added to the bundle.

from cross-fetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.