Skip to content

[HOLD for payment 2023-11-09] [Dev] App bundling fails with CAPTURE_METRICS=true #30565

@hannojg

Description

@hannojg

Details

This PR:

introduced a regression, where when you said CAPTURE_METRICS=true in your env and try to run the app, you'll get the following error:

 BUNDLE  ./index.js 

error: index.js: Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.

  plugins: [
    ['some-plugin', {}],
    ['some-plugin', {}, 'some unique name'],
  ]

Duplicates detected are:
[
  {
    "alias": "/Users/hannomargelo/Documents/Github/expensify-app-fork/node_modules/babel-plugin-module-resolver/lib/index.js",
    "options": {
      "extensions": [
        ".native.js",
        ".native.jsx",
        ".native.ts",
        ".native.tsx",
        ".js",
        ".jsx",
        ".ts",
        ".tsx",
        ".ios.js",
        ".ios.jsx",
        ".ios.ts",
        ".ios.tsx",
        ".android.js",
        ".android.jsx",
        ".android.ts",
        ".android.tx"
      ],
      "alias": {
        "@assets": "./assets",
        "@components": "./src/components",
        "@hooks": "./src/hooks",
        "@libs": "./src/libs",
        "@navigation": "./src/libs/Navigation",
        "@pages": "./src/pages",
        "@styles": "./src/styles",
        "@src": "./src",
        "@userActions": "./src/libs/actions"
      }
    },
    "dirname": "/Users/hannomargelo/Documents/Github/expensify-app-fork",
    "ownPass": false,
    "file": {
      "request": "module-resolver",
      "resolved": "/Users/hannomargelo/Documents/Github/expensify-app-fork/node_modules/babel-plugin-module-resolver/lib/index.js"
    }
  },
  {
    "alias": "/Users/hannomargelo/Documents/Github/expensify-app-fork/node_modules/babel-plugin-module-resolver/lib/index.js",
    "options": {
      "root": [
        "./"
      ],
      "alias": {
        "ReactNativeRenderer-prod": "/Users/hannomargelo/Documents/Github/expensify-app-fork/node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-profiling",
        "scheduler/tracing": "scheduler/tracing-profiling"
      }
    },
    "dirname": "/Users/hannomargelo/Documents/Github/expensify-app-fork",
    "ownPass": false,
    "file": {
      "request": "module-resolver",
      "resolved": "/Users/hannomargelo/Documents/Github/expensify-app-fork/node_modules/babel-plugin-module-resolver/lib/index.js"
    }
  }
]

Reason / solution

This is because if CAPTURE_METRICS in babel.config we push a second instance of the module-resolver plugin. Before the PR it was the only instance, and thus it was working:

App/babel.config.js

Lines 88 to 93 in 2707647

if (process.env.CAPTURE_METRICS === 'true') {
const path = require('path');
const profilingRenderer = path.resolve(__dirname, './node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-profiling');
metro.plugins.push([
'module-resolver',

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting PaymentAuto-added when associated PR is deployed to productionWeeklyKSv2

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions