repack icon indicating copy to clipboard operation
repack copied to clipboard

@callstack/repack/babel-swc-loader make some lib not working

Open npcv1999 opened this issue 2 months ago • 2 comments

Describe the bug

I used the new config in rspack.config.mjs:

module: {
  rules: [
    {
      test: /.[cm]?[jt]sx?$/,
      type: "javascript/auto",
      use: {
        loader: "@callstack/repack/babel-swc-loader",
        parallel: true,
        options: {},
      },
    },
    ...Repack.getAssetTransformRules(),
  ],
}

However, I got an error where react-native-mmkv couldn’t retrieve data saved in storage, and when use @hot-updater/react-native that crash after receive new updater When I switched back to the old config:

...Repack.getJsTransformRules(),
...Repack.getAssetTransformRules()

everything worked fine. I’d like to know why this happens.

System Info

System:
  OS: macOS 15.6.1
  CPU: (12) arm64 Apple M4 Pro
  Memory: 103.22 MB / 24.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.18.1
    path: /Users/ving/.nvm/versions/node/v20.18.1/bin/node
  Yarn: Not Found
  npm:
    version: 10.8.2
    path: /Users/ving/.nvm/versions/node/v20.18.1/bin/npm
  Watchman:
    version: 2024.12.02.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/ving/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.0
      - iOS 26.0
      - macOS 26.0
      - tvOS 26.0
      - visionOS 26.0
      - watchOS 26.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.26094.121.2513.14007798
  Xcode:
    version: 26.0.1/17A400
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/bin/javac
  Ruby:
    version: 3.2.6
    path: /Users/ving/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 18.0.0
    wanted: 18.0.0
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.79.2
    wanted: 0.79.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Re.Pack Version

5.2.1

Reproduction

none

Steps to reproduce

none

npcv1999 avatar Nov 05 '25 17:11 npcv1999

Hi @npcv1999

babel-swc-loader utilizes both babel & swc and should have the most compatible output, could you please show your babel.config.js if it contains any additional stuff that might be influencing the build?

jbroma avatar Nov 06 '25 12:11 jbroma

Hi @jbroma , here is my babel.config.js

const fs = require("fs");
const path = require("path");

function getDynamicAliases(srcPath) {
  const folders = fs
    .readdirSync(srcPath, { withFileTypes: true })
    .filter((dirent) => dirent.isDirectory())
    .map((dirent) => dirent.name);

  // Tạo object paths
  const paths = folders.reduce((acc, folder) => {
    acc[`@${folder}`] = `./src/${folder}`;
    return acc;
  }, {});
  return paths;
}

const ReactCompilerConfig = {
  target: "19",
};

module.exports = {
  presets: ["module:@react-native/babel-preset"],
  env: {
    production: {
      plugins: ["transform-remove-console"],
    },
  },
  plugins: [
    ["babel-plugin-react-compiler", ReactCompilerConfig],
    '@babel/plugin-syntax-jsx',
    ["transform-inline-environment-variables"],
    ["module:react-native-dotenv"],
    [
      "module-resolver",
      {
        extensions: [".tsx", ".ts", ".js", ".json"],
        alias: {
          ...getDynamicAliases(path.resolve(__dirname, "src")),
        },
      },
    ],
    "react-native-reanimated/plugin",
  ],
};

npcv1999 avatar Nov 06 '25 15:11 npcv1999