-
Notifications
You must be signed in to change notification settings - Fork 133
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
TypeError: Cannot convert undefined or null to object (When I try run it on web browser with expo) #14
Comments
Duplicate of #10 If you want help, please upload a minimal repo example. This should be solved in the latest version of Moti, is it not? |
This seems like a reanimated issue; the stack trace is showing |
I use the latest version of Moti, its 0.4.1 |
Yeah I think so |
I'll see if I can get to the bottom of it, thanks! |
@cmaycumber interestingly, this problem happens in an expo app, but not in our I'm going to try upgrading RNW to see if that helps. |
To reproduce this bug:
|
Maybe it could have something to do with the files after they're built by react-native-bob. The webpack resolves directly to the src/index.ts. That would be my best guess without looking at it. I'll try to reproduce this on my end real quick. Let me know if upgrading RNW helps. |
What if we added the babel plugin for react-native-reanimated into the babel.config.js at the root that bob uses for the build? |
Ohh interesting idea. Does Babel get used at a build step? |
I find it odd that Moti doesn't have this issue in my Expo + Next.js app. |
Yeah, this is odd. I thought the same thing when you mentioned you use it in your app. I haven't started using it in mine but I expect I'd see the same problem.
I think bob uses babel to compile all the source files when you run |
It looks like Expo Web uses the lib/module folder. I use next-transpile-modules, so my guess is that next is using my Babel config on Moti and that's why it works. @cmaycumber as you suggested, I think adding the Babel config in Bob could work. Let me know if you confirm that they use it. |
This is from the bob docs for the module target:
Sadly, changing the babel config hasn't worked for me yet. After packing and running it locally but I'm going to clear my |
Looking into the lib code of modules, it seems like it's no longer calling What if we point to the commonJS folder instead? I'm not really familiar with the differences. |
Alright, well I got it to work by adding this to the example:
const createExpoWebpackConfigAsync = require("@expo/webpack-config");
module.exports = async function (env, argv) {
const config = await createExpoWebpackConfigAsync(env, argv);
config.module.rules.push({
test: /\.(js|ts|tsx)$/,
exclude: /node_modules\/(?!(moti|@motify)\/).*/,
use: "babel-loader",
});
return config;
}; I don't love this solution, since it adds quite a bit of config to the user, and I'm not knowledgeable enough about webpack/babel to know if this is a good idea. Honestly, not sure. That said, it does make the example start, so there is some progress. Basically, the issue is, Reanimated's babel plugin is not applying to @EvanBacon if you don't mind, could you tell me if the code sample above is a bad idea for Expo Web? I'm having a problem where Reanimated 2's Babel plugin isn't working on web, since the Babel plugin is ignoring Moti. It seems like I need a way to transpile Moti using our If you aren't sure, I can open an issue on Reanimated. Thanks! |
I opened a discussion here: software-mansion/react-native-reanimated#1715 |
@simpleshadow I saw you liked my comment – did this solution work for you, by chance? |
I think I found the right answer, thanks to the const createExpoWebpackConfigAsync = require("@expo/webpack-config");
module.exports = async function (env, argv) {
const config = await createExpoWebpackConfigAsync(
{
...env,
babel: { dangerouslyAddModulePathsToTranspile: ["moti"] },
},
argv
);
return config;
}; Expo lets you pass a custom set of node modules to transpile with Could everyone here please try this solution? |
Solution added to docs: https://moti-5qbvkhyh8.vercel.app/web#expo-web-support |
Any pointers on avoiding I'm not entirely sure where that To be clear, it does work on Expo Go & Expo Web (SDK 43) now, thanks to this GH issue, but not yet for Next.js If no suggestion comes to mind, should I make another issue as this is related to use of moti in next.js? Things already done / tried:
Used versions & configs
babel.config.jsmodule.exports = {
presets: ['@expo/next-adapter/babel'],
plugins: [
'react-native-reanimated/plugin',
'@babel/plugin-proposal-class-properties',
],
}; next.config.jsconst { withExpo } = require('@expo/next-adapter');
const withFonts = require('next-fonts');
const withPlugins = require('next-compose-plugins');
const withTM = require('next-transpile-modules')([
'moti',
'@motify/core',
'@motify/components',
]);
module.exports = withPlugins(
[withTM, withFonts, [withExpo, { projectRoot: __dirname }]],
{
typescript: {
ignoreBuildErrors: true,
},
},
); Minimal repro issuesIt's also very hard to create a minimal repro since
|
@codinsonn any shot you could try to clone this and use it to repro? https://github.com/axeldelafosse/expo-next-monorepo-example |
On it ⏳ |
I actually had this issue myself yesterday, but with normal reanimated. It seemed that passing |
@nandorojo Hmm, I seem to be unable to reproduce the issue with the monorepo you suggested 🤷♂️ But, since it does seem to work there, I guess I'll try copying some of the configs and versions used to see if it fixes it in my current project. If I find what eventually was the issue, I'll post an update here ⏳ |
Yeah, I think it’s because expo and next requires a monorepo with separate entry points and very particular Babel configs (root of the monorepo, and a unique config in each entry point) |
The text was updated successfully, but these errors were encountered: