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

Duplicate __self prop found #198

Closed
matinzd opened this issue May 3, 2024 · 12 comments · Fixed by #216
Closed

Duplicate __self prop found #198

matinzd opened this issue May 3, 2024 · 12 comments · Fixed by #216

Comments

@matinzd
Copy link
Collaborator

matinzd commented May 3, 2024

Description

After building the app, when metro tries to bundle the app it fails with the following error:

2024-05-03 07:02:12.186 [error] src/app/App.tsx: /Users/****/work/kreddy-frontend/apps/kreddy-mobile/src/app/App.tsx: Duplicate __self prop found. You are most likely using the deprecated transform-react-jsx-self Babel plugin. Both __source and __self are automatically set when using the automatic runtime. Please remove transform-react-jsx-source and transform-react-jsx-self from your Babel config.
  54 |           <SafeAreaProvider>
  55 |             {Platform.OS === 'android' && (
> 56 |               <StatusBar
     |               ^
  57 |                 barStyle="dark-content"
  58 |                 backgroundColor={'transparent'}
  59 |                 animated

Might be related to monorepo stuff since I am using NX.

Metro Config:

const { withNxMetro } = require('@nx/react-native');
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');

const defaultConfig = getDefaultConfig(__dirname);
const { assetExts, sourceExts } = defaultConfig.resolver;

/**
 * Metro configuration
 * https://reactnative.dev/docs/metro
 *
 * @type {import('metro-config').MetroConfig}
 */
const customConfig = {
  transformer: {
    babelTransformerPath: require.resolve('react-native-svg-transformer'),
  },
  resolver: {
    assetExts: assetExts.filter((ext) => ext !== 'svg'),
    sourceExts: [...sourceExts, 'cjs', 'mjs', 'svg'],
  },
};

module.exports = withNxMetro(mergeConfig(defaultConfig, customConfig), {
  // Change this to true to see debugging info.
  // Useful if you have issues resolving modules
  debug: false,
  // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx', 'json'
  extensions: [],
  // Specify folders to watch, in addition to Nx defaults (workspace libraries and node_modules)
  watchFolders: [],
});

My babel config:

module.exports = function (api) {
  api.cache(true);

  if (
    (process.env.NX_TASK_TARGET_TARGET !== undefined &&
      process.env.NX_TASK_TARGET_TARGET === 'build') ||
    process.env.NX_TASK_TARGET_TARGET?.includes('storybook')
  ) {
    return {
      presets: [
        [
          '@nx/react/babel',
          {
            runtime: 'automatic',
          },
        ],
      ],
      plugins: [
        '@babel/plugin-proposal-export-namespace-from',
        'react-native-reanimated/plugin',
      ],
    };
  }

  return {
    presets: [
      ['module:@react-native/babel-preset', { useTransformReactJSX: true }],
    ],
    plugins: ['react-native-reanimated/plugin'],
  };
};

Screenshot

Screenshot 2024-05-03 at 07 06 31

Environment

React Native IDE: 0.0.9
React Native: 0.74.0

@matinzd
Copy link
Collaborator Author

matinzd commented May 3, 2024

@matinzd
Copy link
Collaborator Author

matinzd commented May 3, 2024

Tried commenting out the L16:L17 and it fixed the issue for me. Do you think it's still relevant to pull the dev version of @babel/plugin-transform-react-jsx?

https://github.com/software-mansion/react-native-ide/blob/ce69fd839e386a63a908003ecd0771c8a24b9c4c/packages/vscode-extension/lib/babel_transformer.js#L16-L17

@subramanian-elavathur
Copy link
Collaborator

Description

Seeing the same error as @matinzd however on a standard react native app created from the react-native-cli.

[error] src/App.tsx: /Users/**/Workspace/my-app/src/App.tsx: Duplicate __self prop found. You are most likely using the deprecated transform-react-jsx-self Babel plugin. Both __source and __self are automatically set when using the automatic runtime. Please remove transform-react-jsx-source and transform-react-jsx-self from your Babel config.
  41 |           }}>
  42 |           <PortalProvider>
> 43 |             <Navigation />
     |             ^^^^^^^^^^^^^^
  44 |             <Calendar />
  45 |             <PortalHost name={BOTTOM_SHEET_PORTAL} />
  46 |             {/* {__DEV__ ? null : (

babel.config.js

module.exports = {
  presets: ['module:@react-native/babel-preset'],
  plugins: ['react-native-reanimated/plugin'],
};

metro.config.js

const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');

const defaultConfig = getDefaultConfig(__dirname);
const {assetExts, sourceExts} = defaultConfig.resolver;

/**
 * Metro configuration
 * https://facebook.github.io/metro/docs/configuration
 *
 * @type {import('metro-config').MetroConfig}
 */
const config = {
  transformer: {
    babelTransformerPath: require.resolve('react-native-svg-transformer'),
  },
  resolver: {
    assetExts: assetExts.filter(ext => ext !== 'svg'),
    sourceExts: [...sourceExts, 'svg'],
  },
};

module.exports = mergeConfig(defaultConfig, config);

Environment

React Native IDE: 0.0.9
React Native: 0.73.7

@rocket13011
Copy link
Collaborator

Same Error :

babel.config.js

module.exports = {
  presets: ['module:@react-native/babel-preset'],
  plugins: [
    'react-native-reanimated/plugin',
    [
      "babel-plugin-root-import",
      {
        "rootPathSuffix": "src", // Assuming you put all the code in Src folder
        "rootPathPrefix": "@pc/"
      }
    ]
  ]
};

metro.config.js

const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
const defaultConfig = getDefaultConfig(__dirname);
const { assetExts, sourceExts } = defaultConfig.resolver;

/**
 * Metro configuration
 * https://reactnative.dev/docs/metro
 *
 * @type {import('metro-config').MetroConfig}
 */
const config = {
    transformer: {
      babelTransformerPath: require.resolve("react-native-svg-transformer")
    },
    resolver: {
      assetExts: assetExts.filter((ext) => ext !== "svg"),
      sourceExts: [...sourceExts, "svg"]
    }
  };

module.exports = mergeConfig(defaultConfig, config);

Environment

React Native IDE: 0.0.9
React Native: 0.74.0

@Martinocom
Copy link
Collaborator

I have the same error on my personal project, but not the company one. Dependencies are the same, but in one App.tsx is in the root, in the other in the src folder. I check the dependencies of both and are pretty the same, expect for some fewer or different libraries used in my own project.

Not related to code btw, because removing everything and leaving the app with only a <View /> will result in the same error.

@matinzd
Copy link
Collaborator Author

matinzd commented May 6, 2024

Something to add here same as @Martinocom. My app entrypoint is located under src/main.tsx and I have configured it in build gradle and xcode.env:

entryFile = file("../../src/main.tsx")
export ENTRY_FILE="${PROJECT_DIR}/../src/main.tsx"

@matinzd
Copy link
Collaborator Author

matinzd commented May 6, 2024

@CoryWritesCode
Copy link
Collaborator

same issue as above on iOS builds

kmagiera added a commit that referenced this issue May 8, 2024
Fixes #198 

This is another approach at resolving the complexity of enabling
development JSX transforms.

As noted in #198 the old approach would sometimes produce an error that
the development transform throws when other instance of dev JSX
transform run, or when some of jsx-self or jsx-source transforms are run
on the same file along with the jsx dev version.

The problem in the repro provided in #198 was due to the use of quite
popular react-native-svg-transformer which doesn't forward `plugins`
attribute to the upstream transformer. I proposed a fix for this issue
in that repo
kristerkari/react-native-svg-transformer#354
however, it isn't practical to wait for a fix there and hence the PR
implements another workaround that doesn't depend on the `plugins`
attribute of the transformer.

The new approach relies on additional flag that is turned on when
non-dev version of the plugin is loaded. What we try to achieve is that
only jsx-dev transform is listed as plugin, and other varians (non-dev,
-self, and -source) versions are all turned off. Since we can't hijack
the plugins list, the only option is to use require overwrites.
Furthermore, we need to consider the case when someone has a proper
setup where only dev transform is listed and others are not. If we were
to only overwrite non-deb with dev version, that wouldn't suffice for
this particular case.

What we now do is:
1) disable -self and -source transforms entirely (read inline comment
for details on why we can do it)
2) replace non-dev JSX transform with dev version, and also use a flag
to mark when this replaced non-dev version is used
3) replace dev JSX transform with extra logic that checks for the flag
that marks whether non-dev version is used. If it is used, we return an
empty transform. Otherwise, we just return the dev transform as it means
that non-dev isn't registered.

As stated in the inline comment, this approach would break if someone
has dev transform registered before non-dev. Apparently, I don't see a
better way to move forward with this approach and I'd hope that the
current solution would cover the majority of setups.
@kmagiera
Copy link
Member

kmagiera commented May 8, 2024

This issue turned out to be a problem with svg transformer: https://github.com/matinzd/react-native-ide-nx-repro/blob/main/apps/react-native-ide-nx-repro-mobile/metro.config.js#L15

The transformer wasn't forwarding some of the properties to the upstream version of transformer and I submitted a PR to fix that here: kristerkari/react-native-svg-transformer#354

I also found another way to workaround this issue without the need for a fix in svg transformer. Can other people here confirm that you've been using that transformer in your setups?

@subramanian-elavathur
Copy link
Collaborator

subramanian-elavathur commented May 8, 2024

I can confirm we were using react-native-svg-transformer. Thanks for the fix - hope to try the new build soon.

@seanpcoyle
Copy link
Collaborator

This issue turned out to be a problem with svg transformer: https://github.com/matinzd/react-native-ide-nx-repro/blob/main/apps/react-native-ide-nx-repro-mobile/metro.config.js#L15

The transformer wasn't forwarding some of the properties to the upstream version of transformer and I submitted a PR to fix that here: kristerkari/react-native-svg-transformer#354

I also found another way to workaround this issue without the need for a fix in svg transformer. Can other people here confirm that you've been using that transformer in your setups?

I was running into this issue and I can confirm that I am also using react-native-svg-transformer.

@phuongnn1996
Copy link

Tried commenting out the L16:L17 and it fixed the issue for me. Do you think it's still relevant to pull the dev version of @babel/plugin-transform-react-jsx?

https://github.com/software-mansion/react-native-ide/blob/ce69fd839e386a63a908003ecd0771c8a24b9c4c/packages/vscode-extension/lib/babel_transformer.js#L16-L17

Hi. How did you commented it? I'm facing this issue even if I installed react-native-svg-transformer 1.4.0 or commented the babelTransformerPath: require.resolve('react-native-svg-transformer').

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

Successfully merging a pull request may close this issue.

8 participants