-
Notifications
You must be signed in to change notification settings - Fork 55
Description
Integrating the Datadog React Native SDK in an Expo application introduces a runtime error where modules exporting a default function (e.g., dayjs) are wrapped incorrectly during bundling. The resulting runtime error is:
0, dayjs.default.default is not a function (it is undefined)
The error only occurs when the Datadog instrumentation is enabled. Without the Datadog Babel/Metro integration the application works normally.
Environment
- Expo SDK: ^54.0.7
- React Native: 0.81.5
- Datadog React Native SDK: latest
- Platform: Android
- Metro bundler
- Expo Router
- NativeWind
Observed Behavior
During bundling and runtime execution, the dayjs import becomes:
dayjs.default.default(...)
instead of:
dayjs(...)
This results in the runtime failure:
TypeError: 0, dayjs.default.default is not a function
The issue appears to originate from the Datadog Babel plugin or Metro serializer modifying module exports during instrumentation.
Expected Behavior
Modules exporting a default function should remain callable after Datadog instrumentation.
Example expected usage:
import dayjs from "dayjs";
dayjs(value).format();Current Babel Configuration
module.exports = function (api) {
api.cache(true);
return {
presets: [
['babel-preset-expo', { jsxImportSource: 'nativewind' }],
'nativewind/babel'
],
plugins: [
[
'module-resolver',
{
root: ['./'],
alias: {
'@': './',
'tailwind.config': './tailwind.config.js',
},
},
],
'react-native-worklets/plugin',
[
'@datadog/mobile-react-native-babel-plugin',
{
sessionReplay: {
svgTracking: false
},
components: {
useContent: true,
useNamePrefix: true
}
}
]
]
};
};Current Metro Configuration
const { getDefaultConfig } = require("expo/metro-config");
const { withNativeWind } = require("nativewind/metro");
const { getDatadogExpoConfig } = require("@datadog/mobile-react-native/metro");
const datadogConfig = getDatadogExpoConfig(__dirname);
module.exports = withNativeWind(datadogConfig, {
input: "./global.css",
});Datadog Setup
const config = new DatadogProviderConfiguration(
process.env.EXPO_PUBLIC_DATADOG_CLIENT_TOKEN!,
process.env.EXPO_PUBLIC_DATADOG_ENV!,
TrackingConsent.GRANTED,
{
site: "EU1",
uploadFrequency: UploadFrequency.FREQUENT,
batchSize: BatchSize.SMALL,
verbosity: SdkVerbosity.DEBUG,
rumConfiguration: {
applicationId: process.env.EXPO_PUBLIC_DATADOG_APPLICATION_ID!,
trackInteractions: true,
trackResources: true,
trackErrors: true,
longTaskThresholdMs: 100,
nativeCrashReportEnabled: true,
sessionSampleRate: 100
},
logsConfiguration: {},
traceConfiguration: {}
}
)Used through:
<DatadogProvider configuration={config}>
Notes
- Only one version of
dayjsexists in the dependency tree. - The issue disappears if the Datadog Babel plugin or Metro integration is removed.
- The problem appears related to how the Datadog instrumentation wraps modules exporting default functions.
Request
Guidance on preventing module export rewriting that produces default.default during Datadog instrumentation in Expo environments.