Fix metro failing to resolve @ipld/dag-cbor in dev mode

This commit is contained in:
Oleksii Bulenok
2026-08-14 13:32:57 +02:00
parent 70195d7059
commit 02a5dc2209
2 changed files with 9 additions and 8 deletions
+7 -1
View File
@@ -35,7 +35,13 @@ module.exports = function (api) {
// cannot use `env` field because it will put them after
// the `react-native-worklets/plugin` plugin
...(api.env('test')
? ['@babel/plugin-transform-class-static-block']
? [
'@babel/plugin-transform-class-static-block',
// Compile `import()` to require so jest (which runs without
// `--experimental-vm-modules`) can execute lazily-loaded modules
// like `@ipld/dag-cbor` via its moduleNameMapper.
'@babel/plugin-transform-dynamic-import',
]
: []),
...(api.env('production') ? ['transform-remove-console'] : []),
+2 -7
View File
@@ -123,14 +123,9 @@ function isPlainObject(v: any): boolean {
/**
* Load `@ipld/dag-cbor` on demand. The dynamic `import()` lets web bundlers
* emit it (and its ~190KB `cborg` dependency) as a separate chunk that only
* loads when posting a thread. Under jest (which runs without
* `--experimental-vm-modules`) dynamic import throws, so we fall back to a
* lazy `require`, which resolves through the test moduleNameMapper.
* loads when posting a thread. Under jest this compiles down to a require
* that resolves through the test moduleNameMapper.
*/
function importDagCbor(): Promise<typeof import('@ipld/dag-cbor')> {
if (process.env.NODE_ENV === 'test') {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return Promise.resolve(require('@ipld/dag-cbor'))
}
return import('@ipld/dag-cbor')
}