-
Notifications
You must be signed in to change notification settings - Fork 132
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
Expo React Native does not work with mjs files #47
Comments
This looks similar to #39. The easiest option in my opinion will be to allow |
I mean, there are prettier things :D but if there's no other way, we'll probably leave it at that for now 👍🏻 |
do you know if the same errors occur with react native without expo? |
Sorry, I don't want to change the package.json entrypoint. The current package setup works with almost all common bundlers (including older webpack versions due to nuxt2) and the It will be better to allow loading
I'm not sure. I only briefly tested a react native setup with https://snack.expo.dev/ and it works as expected there. |
Hey I tried to introduce the expo webpack configuration but it didn't fix my error |
@tobicrain Could you post here the exact error message? This weekend I might try to find some time and investigate it further. |
@tobicrain In addition, you may want to check the gist linked in this issue - expo/expo#8809 (comment). Furthermore, as suggested in expo/expo#15836, you could try adding |
@ganigeorgiev Unable to resolve "pocketbase" from "node_modules/pocketbase-react/lib/context/Pocketbase.js" My sdk - pocketbase-react, is using current pocketbase js version. |
From the extensions list in the error message it doesn't seem that Could you reproduce the same error in https://snack.expo.dev/ (for me it works fine there, for both the android and ios emulators)? Maybe this is not an expo issue but a TypeScript one because by default TS also cannot load es modules (#34). In newer TS versions there is now In any case, if you want to use the legacy cjs module, you can also try importing it directly like: import PocketBase from 'pocketbase/cjs' But I don't recommend the above - you should either use es modules and import style statements or cjs and require style statements. |
yeah I tried everything to avoid forking the sdk, but because I have to dynamically decide which import to use, I had to fork it |
I don't understand what do you mean by "I have to dynamically decide which import to use". Providing always the cjs as As mentioned earlier, registering the mjs in your bundler config should resolve the issue. Without any context it's really hard to reproduce it because there are a lot of dependencies involved (are you using babel, ts and/or other transpilers?). |
And that doesn't help me because I only want to import "pocketbase/cjs" if the sdk is used in react native, otherwise "pocketbase" is fine. I'll try to recreate the whole thing with expo snack and send it to you |
@ganigeorgiev |
I'm not sure what the above package is supposed to test. I'm not able to run it locally but that's because there seems to be some dependency misconfiguration (I'm not sure how it works in expo snack): [gani@dev happy-salsa]$ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: undefined@undefined
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR! react@"18.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.12.0" from pocketbase-react@0.1.3
npm ERR! node_modules/pocketbase-react
npm ERR! pocketbase-react@"0.1.3" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/gani/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/gani/.npm/_logs/2022-10-13T07_22_56_536Z-debug-0.log Additionally the above seems to use |
@tobicrain Here is a minimal js example - https://snack.expo.dev/@jiviba8897/e35de5. Please test it and if the above works, then probably the issue is somewhere else (most likely a transpiler(s) misconfiguration depending on whether you are using babel, ts, etc.). |
isnt working either when running locally, on expo snack its working fine |
@tobicrain Are you getting the same |
@tobicrain Thank you. I was able to borrow a newer android device and I've installed expo go and indeed I was faced with the same error during build (strangely there are no errors when I run it with the android studio emulator...). Anyway, now that I'm able to reproduce the error I'll try to spend some time to debug it and will get back to you soon. |
@ganigeorgiev Glad to hear that. Alright, thank you very much |
@tobicrain I was able to make it work by creating a // metro.config.js
const { getDefaultConfig } = require('expo/metro-config');
const config = getDefaultConfig(__dirname);
config.resolver.sourceExts.push('mjs');
module.exports = config; I'm not sure why react native doesn't support the extension by default (it is officially recognized by the node/es specs, including cjs), but in any case the If you are still not able to make it work, please let me know and I'll investigate it further. |
@tobicrain Just for info, I've also pushed a fix in the sdk related to #42, so you may want to update your dependencies. |
How do you load pocketbase-react, using |
@tobicrain Just to make sure that the error is not caused by my latest changes in v0.7.3 could you try to downgrade your SDK version to v0.7.2? |
@tobicrain Just to let you know that in v0.7.4 the additional |
@ganigeorgiev I'm using React native with mjs and everything works fine, but when testing i have to use the cjs format because jest doesn't support ESmodules, i have been debugging for the past 4 hours trying to get it to work, so i just decided to use the cjs file only for testing, and other errors start popping up, after checking the library source code turned out in |
Because as far as I know CJS can't have more than 1 default import, aka. it will require exporting it as some sort of nested object and not just In general, the CJS bundle exists just for backward compatibility with older node versions and legacy bundler configurations and the ES bundle should be preferred when possible. Unfortunately I don't have much experience with Jest and I'm not sure what exactly are its issues with ES modules but there seems to be some experimental support based on https://jestjs.io/docs/ecmascript-modules. |
I don't have much knowledge about this, but my issue was fixed editing the {
input: "src/index.ts",
output: [
{
name: "PocketBase",
file: "dist/pocketbase.cjs.js",
format: "cjs",
exports: "named",
sourcemap: isProduction,
},
],
plugins: basePlugins(),
watch: { clearScreen: false },
} |
But that's exactly what I meant, aka. you can't have both default and named exports, and the above I think will be returned as an object, which will defer from how the ES bundle is exported. |
By using the SDK with Expo (in my Pocketbase React SDK), Jest/Expo does not currently support MJS files. Maybe there is a way to replace the default entry ("main": "./dist/pocketbase.es.mjs") with something similar, also supported by Jest
The text was updated successfully, but these errors were encountered: