How to mock a package if not supported in web

I am woking on expo web bare work flow.
I am getting this error from one of my libraries which works fine on ios and android.But for web its giving errors.

/Users/..../node_modules/@valdio/react-native-scrollable-tabview/lib/index.js 134:13
Module parse failed: Unexpected token (134:13)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|       return React.cloneElement(this.props.renderTabBar(props), props)
|     } else {
>       return <DefaultTabBar {...props} />
|     }
|   }

I do not want to use this libary in web, but code is not able to compile. Should I import packages based on Platform.OS === ‘web’. or should I mock this package somehow.

Please suggest.

Hi

In the code where you are referencing this library, what does it look like?

There are, I think, two ways to go about this.

  1. Using Platform.OS
  2. Writing files like Component1.native.js, Component1.web.js etc.

See this page for some examples.

1 Like

Thanks. I will give 2nd a try.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.