Git Product home page Git Product logo

Comments (2)

arjunvegda avatar arjunvegda commented on August 11, 2024

Root cause: Metro — expo's bundler is unable to resolve the multi-entry node module paths using exports field correctly (most probably due to jotai-devtools's ./dist?).

Ideally this should be fixed by turning on the unstable_enablePackageExports option but I couldn't make it work using config.resolver.unstable_enablePackageExports = true so I'd suggest filing an issue with Metro and getting their recommendation as well.

Here are a few fixes I could think of.

Fix 1 (recommended)

Expo users would resolve the path (jotai-devtools/utils) manually by configuring metro.config.js. Retains type safety for jotai-devtools/utils.

// metro.config.js
const path = require('path');
const { getDefaultConfig } = require('expo/metro-config');

const config = getDefaultConfig(__dirname);
config.resolver.resolveRequest = (context, moduleName, platform) => {
    if (moduleName === 'jotai-devtools/utils') {
        return {
            filePath: path.resolve(__dirname, 'node_modules/jotai-devtools/dist/utils.cjs.js'),
            type: 'sourceFile',
        };
    }

    return context.resolveRequest(context, moduleName, platform);
}
module.exports = config

Fix 2 (requires further investigation)

We add react-native field to jotai-devtools's package.json file to help metro resolve modules correctly.
The caveat is that it only supports a string value.

Add this in jotai-devtools/package.json

"react-native": "./dist/utils.cjs.js"

Outstanding questions

  • How do we export the correct types i.e. ./dist/utils.d.ts for react-native property?
  • How do we add support for ESM? Does Metro support it?

I'm not a React-native expert by any means 😅 so it'd be great if someone could help me test if the hooks under jotai-devtools/utils work as expected 🙏

from jotai-devtools.

arjunvegda avatar arjunvegda commented on August 11, 2024

Closing this as we have a good workaround for now. Happy to re-open if the issue persists.

from jotai-devtools.

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.