Files
self/app/babel.config.cjs
Nesopie ab5f584210 fix(app): rewrite tsup __require to require for Metro bundling (#1810)
tsup wraps require() as __require() in ESM builds for externalized
modules. Metro's dependency collector only recognizes standard require()
calls, so __require() calls for .lottie assets are invisible during
bundling, causing "Unknown named module" errors at runtime.

This Babel plugin converts __require(stringLiteral) back to
require(stringLiteral) before Metro's dependency collection pass,
allowing the custom resolver to properly locate and bundle .lottie
assets from the SDK dist.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 06:25:42 -08:00

57 lines
1.5 KiB
JavaScript

// SPDX-FileCopyrightText: 2025-2026 Social Connect Labs, Inc.
// SPDX-License-Identifier: BUSL-1.1
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
// tsup wraps require() as __require() in ESM builds for externalized modules.
// Metro's dependency collector only recognizes standard require() calls, so __require()
// calls are invisible to bundling. This plugin converts them back to require() so Metro
// can resolve and include the assets (e.g. .lottie files from the SDK dist).
function rewriteDunderRequire() {
return {
visitor: {
CallExpression(path) {
if (
path.node.callee.type === 'Identifier' &&
path.node.callee.name === '__require' &&
path.node.arguments.length === 1 &&
path.node.arguments[0].type === 'StringLiteral'
) {
path.node.callee.name = 'require';
}
},
},
};
}
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: [
rewriteDunderRequire,
[
'module-resolver',
{
root: ['./src'],
alias: { '@': './src' },
},
],
['@babel/plugin-transform-private-methods', { loose: true }],
'@babel/plugin-transform-export-namespace-from',
[
'module:react-native-dotenv',
{
moduleName: '@env',
path: '.env',
blacklist: null,
whitelist: null,
safe: false,
allowUndefined: true,
},
],
],
env: {
production: {
plugins: ['transform-remove-console'],
},
},
};