Skip to content
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

Doesn't Compile #242

Open
AlexBasile123 opened this issue Apr 10, 2021 · 4 comments
Open

Doesn't Compile #242

AlexBasile123 opened this issue Apr 10, 2021 · 4 comments

Comments

@AlexBasile123
Copy link

I wanted to use your component.

I'm getting compilations errors after adding: "import SegmentedControl from '@react-native-segmented-control/segmented-control/SegmentedControl.js';" to my js file.

I'm running on a Mac.

I've followed the installation instructions. I can see the module in node_modules.

Please advise.

-------------------------- Error Message ----------------------------

react-scripts build

Creating an optimized production build...
Failed to compile.

./node_modules/@react-native-segmented-control/segmented-control/js/SegmentedControl.js
SyntaxError: /Users/alexbasile/jars_workspace/src/gitlab.com/jarsgroup/ras.gg/node_modules/@react-native-segmented-control/segmented-control/js/SegmentedControl.js: Unexpected token (18:12)

16 | } from 'react-native';
17 |

18 | import type {SegmentedControlProps} from './types';
| ^
19 | import {SegmentedControlTab} from './SegmentedControlTab';
20 | import {SegmentsSeparators} from './SegmentsSeparators';
21 |
at parser.next ()

@zifahm
Copy link

zifahm commented Apr 30, 2021

Same here using it with react-native-web

@ihor-zhvanko
Copy link

ihor-zhvanko commented Jul 21, 2021

Also had an issue in segmented-input with react-native-web. Just modify your webpack.config.js where you configure your babel loader:

// Add every directory that needs to be compiled by Babel during the build.
  include: [
    path.resolve(appDirectory, 'index.web.js'),
    path.resolve(appDirectory, 'src'),
    // extra modules to compile 
    path.resolve(appDirectory, 'node_modules/@react-native-segmented-control/segmented-control'),
  ],

Adding this solves the problem:

path.resolve(appDirectory, 'node_modules/@react-native-segmented-control/segmented-control'),

@balgamat
Copy link

balgamat commented Oct 3, 2023

I needed to make this work with NextJS and achieved that using a webpack loader, that strips away the flow types (which is the root cause of the problem:

  1. install the loader with yarn -D add remove-flow-types-loader
  2. Adjust webpack config (e.g. in next.config.js)
webpack: c => {
      c.module.rules.push({
        test: /\.jsx?$/,
        use: ['remove-flow-types-loader'],
      });
      return c;
    },

Solution with babel will be similar. Hope this helps!

@conor-ob
Copy link

I needed to make this work with NextJS and achieved that using a webpack loader, that strips away the flow types (which is the root cause of the problem:

Thanks @balgamat your solution helped me get most of the way. I have a similar use case with @expo/next-adapter

I also had to add the package to transpilePackages in next.config.js so my full solution looks like this:

const nextConfig = {
  reactStrictMode: false,
  transpilePackages: [
    '@react-native-segmented-control/segmented-control',
    // blah blah blah...
  ],
  webpack: (c) => {
    c.module.rules.push({
      test: /\.jsx?$/,
      use: ['remove-flow-types-loader']
    })
    return c
  }
}

module.exports = withExpo(nextConfig)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants