Skip to content

Commit d6460cc

Browse files
authored
Fix @babel/runtime issues (#836)
* Add `@babel/runtime` as dependancy * Revert "Add `@babel/runtime` as dependancy" This reverts commit 693d8c5. * `disableImportExportTransform` in babel config * Fix to tests * Change how reanimated is polyfilled
1 parent 2a8f8b7 commit d6460cc

9 files changed

+116
-44
lines changed

packages/core/babel.config.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
module.exports = {
2-
presets: ["module:metro-react-native-babel-preset"],
3-
plugins: [
4-
"@babel/plugin-proposal-export-namespace-from",
5-
"react-native-reanimated/plugin",
6-
],
1+
module.exports = (api) => {
2+
const isTest = api.env("test");
3+
4+
return {
5+
presets: [
6+
[
7+
"module:metro-react-native-babel-preset",
8+
{
9+
/**
10+
* Addresses issue caused on snack that leads to `Unable to resolve module 'app/node_modules/@babel/runtime/helpers/interopRequireDefault.js'`
11+
* See: https://github.com/expo/snack/pull/302
12+
* Always false for tests for jest to work
13+
*/
14+
disableImportExportTransform: !isTest,
15+
},
16+
],
17+
],
18+
plugins: [
19+
"@babel/plugin-proposal-export-namespace-from",
20+
"react-native-reanimated/plugin",
21+
],
22+
};
723
};

packages/maps/babel.config.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
module.exports = {
2-
presets: ["module:metro-react-native-babel-preset"],
1+
module.exports = (api) => {
2+
const isTest = api.env("test");
3+
4+
return {
5+
presets: [
6+
[
7+
"module:metro-react-native-babel-preset",
8+
{
9+
/**
10+
* Addresses issue caused on snack that leads to `Unable to resolve module 'app/node_modules/@babel/runtime/helpers/interopRequireDefault.js'`
11+
* See: https://github.com/expo/snack/pull/302
12+
* Always false for tests for jest to work
13+
*/
14+
disableImportExportTransform: !isTest,
15+
},
16+
],
17+
],
18+
};
319
};

packages/native/babel.config.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
module.exports = {
2-
presets: ["module:metro-react-native-babel-preset"],
1+
module.exports = (api) => {
2+
const isTest = api.env("test");
3+
4+
return {
5+
presets: [
6+
[
7+
"module:metro-react-native-babel-preset",
8+
{
9+
/**
10+
* Addresses issue caused on snack that leads to `Unable to resolve module 'app/node_modules/@babel/runtime/helpers/interopRequireDefault.js'`
11+
* See: https://github.com/expo/snack/pull/302
12+
* Always false for tests for jest to work
13+
*/
14+
disableImportExportTransform: !isTest,
15+
},
16+
],
17+
],
18+
};
319
};

packages/types/babel.config.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
module.exports = {
2-
presets: ["module:metro-react-native-babel-preset"],
1+
module.exports = (api) => {
2+
const isTest = api.env("test");
3+
4+
return {
5+
presets: [
6+
[
7+
"module:metro-react-native-babel-preset",
8+
{
9+
/**
10+
* Addresses issue caused on snack that leads to `Unable to resolve module 'app/node_modules/@babel/runtime/helpers/interopRequireDefault.js'`
11+
* See: https://github.com/expo/snack/pull/302
12+
* Always false for tests for jest to work
13+
*/
14+
disableImportExportTransform: !isTest,
15+
},
16+
],
17+
],
18+
};
319
};

packages/ui/babel.config.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
module.exports = {
2-
presets: ["module:metro-react-native-babel-preset"],
3-
plugins: [
4-
"@babel/plugin-proposal-export-namespace-from",
5-
"react-native-reanimated/plugin",
6-
],
1+
module.exports = (api) => {
2+
const isTest = api.env("test");
3+
4+
return {
5+
presets: [
6+
[
7+
"module:metro-react-native-babel-preset",
8+
{
9+
/**
10+
* Addresses issue caused on snack that leads to `Unable to resolve module 'app/node_modules/@babel/runtime/helpers/interopRequireDefault.js'`
11+
* See: https://github.com/expo/snack/pull/302
12+
* Always false for tests for jest to work
13+
*/
14+
disableImportExportTransform: !isTest,
15+
},
16+
],
17+
],
18+
plugins: [
19+
"@babel/plugin-proposal-export-namespace-from",
20+
"react-native-reanimated/plugin",
21+
],
22+
};
723
};

packages/ui/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"scripts": {
1919
"clean": "rimraf lib",
2020
"clean:modules": "rimraf node_modules",
21-
"build:commonjs": "../../node_modules/.bin/babel src --out-dir lib/commonjs --extensions .tsx,.ts,.js,.jsx && ts-node scripts/polyfillReanimatedWorkletInitForSnack.ts",
21+
"build:commonjs": "../../node_modules/.bin/babel src --out-dir lib/commonjs --extensions .tsx,.ts,.js,.jsx",
2222
"build": "yarn clean && yarn build:commonjs && yarn tsc",
2323
"test": "jest",
2424
"test:coverage": "jest --coverage"

packages/ui/scripts/polyfillReanimatedWorkletInitForSnack.ts

-25
This file was deleted.

packages/ui/src/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./polyfillReanimatedWorkletInit";
12
import { Icon } from "@draftbit/native";
23
export { Icon, LinearGradient, WebView } from "@draftbit/native";
34

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* When the @draftbit/ui is used with snack, we run into the error: 'r.g.__reanimatedWorkletInit is not a function'
3+
* The solution is to add a polyfill for the global.__reanimatedWorkletInit function
4+
* https://forums.expo.dev/t/react-native-reanimated-error-r-g-reanimatedworkletinit-is-not-a-function/68222/3
5+
*
6+
* This polyfill needs to be done at the first point of execution, placing at the top of index.tsx does not guarantee that
7+
* since the build reorders the code around (such as hoisting imports/exports) which results in it not being the top most call. Having it as an import of
8+
* a seperate file guarantees it's the first import
9+
*
10+
*/
11+
12+
//@ts-ignore
13+
if (!global.__reanimatedWorkletInit) {
14+
//@ts-ignore
15+
global.__reanimatedWorkletInit = function () {};
16+
}

0 commit comments

Comments
 (0)