nandorojo / moti

🐼 The React Native (+ Web) animation library, powered by Reanimated 3.
https://moti.fyi
MIT License
3.9k stars 120 forks source link

Missing types on Skeleton with react-native-linear-gradient #293

Closed saulojoab closed 1 year ago

saulojoab commented 1 year ago

Is there an existing issue for this?

Current Behavior

I'm trying to import the Skeleton using react-native-linear-gradient like below:

import { Skeleton } from 'moti/skeleton/react-native-linear-gradient';

But I'm getting the following error:

Could not find a declaration file for module 'moti/skeleton/react-native-linear-gradient'. '/Users/saulojoab/dev/eon-repos/eon/node_modules/moti/skeleton/react-native-linear-gradient.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/moti` if it exists or add a new declaration (.d.ts) file containing `declare module 'moti/skeleton/react-native-linear-gradient';

Oddly enough, creating a d.ts declaration file did not work. My app does not break or anything, but the TS error is annoying.

Expected Behavior

Types should be included and no TS error should be shown.

Steps To Reproduce

  1. Install Moti
  2. import { Skeleton } from 'moti/skeleton/react-native-linear-gradient';
  3. Typescript error.

Versions

- Moti: ^0.25.3
- Reanimated: ^3.1.0
- React Native: 0.71.8

Screenshots

image

Reproduction

Doing what I said above should throw the error.

nandorojo commented 1 year ago

can you instead follow the docs for the babel module resolver?

https://moti.fyi/skeleton#option-2-react-native-linear-gradient

saulojoab commented 1 year ago

@nandorojo Sorry, I forgot to mention on the issue: that also does not work, which is why I was importing directly.

This is my babel.config.ts:

export default {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    [
      'module-resolver',
      {
        extensions: ['.ios.js', '.android.js', '.js', '.ts', '.tsx', '.json'],
        root: ['./'],
        alias: {
          '@': './src',
          'moti/skeleton': 'moti/skeleton/react-native-linear-gradient',
        },
      },
    ],
    'react-native-reanimated/plugin',
  ],
};

This give me this super weird Requiring unknown module "46" error.

image

If I remove the moti skeleton alias, everything works fine.

saulojoab commented 1 year ago

Restarting Metro seems to fix the 46 module error. However, It's still trying to use expo-linear-gradient:

Error: Unable to resolve module expo-linear-gradient from /Users/saulojoab/dev/eon-repos/eon/node_modules/moti/build/skeleton/expo.js: expo-linear-gradient could not be found within the project or in these directories:

image

nandorojo commented 1 year ago

can you delete node modules and clear all caches and try again? seems like the resolution isn't working

saulojoab commented 1 year ago

@nandorojo I tried doing that, didn't work.

nothing seems to be working lmao, I'm going insane

kierangillen commented 9 months ago

I also had the same issue when I tried to use the example in the docs.

kierangillen commented 9 months ago

@nandorojo I'm not sure this issue should have been closed.

nandorojo commented 9 months ago

you have to import from moti/skeleton directly after configuring the babel config

saulojoab commented 8 months ago

FYI: I just gave up trying to use react-native-linear-gradient and used the expo package instead.

nandorojo commented 8 months ago

The original issue that was opened here didn’t follow the docs properly which is why it got that TS error. You should still just import from moti/skeleton. But using the expo one is a good solution too