use alias in babel.config.js
Describe the feature
I have a project with alias in babel.config.js file, but I create a npm lib and test, does not recognize the alias.
what am I doing wrong?
babel.config.js:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
'react-native-reanimated/plugin',
'import-glob',
[
'module-resolver',
{
root: ['.'],
extensions: ['.ios.js', '.android.js', '.js', '.jsx', '.ts', '.tsx', '.json'],
alias: {
'@app': './src/app',
'@authScreens': './src/app/screens/Auth/screens',
'@components': './src/app/components',
'@config': './src/config',
'@constants': './src/constants',
'@hooks': './src/app/hooks',
'@interfaces': './src/interfaces',
'@navigationHelper': './src/app/components/AppNavigator/helper',
'@redux': './src/redux',
'@screens': './src/app/screens',
'@services': './src/services',
'@utils': './src/utils',
'@assets': './src/app/assets'
}
}
]
]
};
package.json:
{
"name": "@galicia/aux-galicia-login",
"version": "0.0.1",
"private": true,
"description": "Login screen and components",
"author": "Wolox S.A.",
"scripts": {
"android": "npx react-native run-android --variant=qaDebug",
"ios": "npx react-native run-ios --scheme qa",
"start": "npx react-native start",
"webpack-start": "react-native webpack-start --port 9000",
"test": "jest --passWithNoTests",
"lint": "eslint src --ext .js,.ts,.jsx,.tsx",
"clean": "rm -rf $TMPDIR/react-* && watchman watch-del-all && yarn cache clean",
"force-clean": "yarn run android:clean && yarn run clean && rm -rf ios/build && rm -rf ios/Pods && rm -rf node_modules/ && yarn install && cd ios/ && pod install",
"ios:clean": "cd ios/ && rm -rf build && rm -rf Pods",
"android:clean": "cd android/ && ./gradlew clean",
"android:build.qa": "cd android && ./gradlew clean && ./gradlew assembleQaRelease",
"android:build.stage": "cd android && ./gradlew clean && ./gradlew assembleStageRelease",
"android:build.production": "cd android && ./gradlew clean && ./gradlew assembleProductionRelease",
"android:install.qa": "cd android && ./gradlew clean && ./gradlew assembleQaRelease && ./gradlew installQaRelease",
"test:watch": "jest --watch",
"test:debug": "node --inspect node_modules/.bin/jest --runInBand",
"lint-fix": "eslint src --ext .js,.ts,.jsx,.tsx --fix",
"lint-diff": "git diff --staged --name-only --relative --diff-filter=ACM | grep -E \"\\.(ts|tsx|js|jsx)$\" | xargs eslint",
"check-types": "tsc",
"test:generate-coverage-file": "node ./node_modules/@wolox/js-test-coverage-script",
"test:coverage": "jest --env=jsdom --coverage --passWithNoTests --watchAll=false --silent --coverageThreshold \"{}\" --coverageReporters=\"json-summary\" && yarn run test:generate-coverage-file",
"prepare": "bob build"
},
"dependencies": {
"@hookform/devtools": "^4.0.1",
"@hookform/resolvers": "^2.8.5",
"@react-native-async-storage/async-storage": "^1.15.14",
"@react-native-community/masked-view": "^0.1.11",
"@react-navigation/native": "^6.0.6",
"@react-navigation/stack": "^6.0.11",
"apisauce": "^2.1.5",
"cerealizr": "^1.0.1-alpha",
"expo": ">=44.0.0-0 <45.0.0",
"expo-local-authentication": "^12.1.0",
"i18next": "^21.6.3",
"react": "17.0.2",
"react-error-boundary": "^3.1.4",
"react-hook-form": "^7.22.3",
"react-native": "0.66.4",
"react-native-config": "^1.4.5",
"react-native-exception-handler": "^2.10.10",
"react-native-flipper": "^0.126.0",
"react-native-gesture-handler": "^2.1.0",
"react-native-keyboard-spacer": "^0.4.1",
"react-native-localize": "^2.1.6",
"react-native-reanimated": "^2.3.1",
"react-native-safe-area-context": "^3.3.2",
"react-native-screens": "^3.10.1",
"react-native-splash-screen": "^3.3.0",
"react-native-swiper": "^1.6.0",
"react-redux": "^7.2.6",
"reactotron-apisauce": "^3.0.0",
"reactotron-react-native": "^5.0.1",
"reactotron-redux": "^3.1.3",
"redux": "^4.1.2",
"redux-persist": "^6.0.0",
"redux-persist-seamless-immutable": "^2.0.0",
"redux-recompose": "^3.0.0",
"redux-thunk": "^2.4.1",
"seamless-immutable": "^7.1.4"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/eslint-parser": "^7.16.5",
"@babel/runtime": "^7.12.5",
"@callstack/repack": "^2.5.1",
"@react-native-community/bob": "^0.17.1",
"@react-native-community/eslint-config": "^2.0.0",
"@testing-library/jest-native": "^4.0.4",
"@testing-library/react-native": "^9.0.0",
"@types/jest": "^27.0.3",
"@types/react": "^17.0.38",
"@types/react-native": "^0.66.9",
"@types/react-redux": "^7.1.20",
"@types/react-test-renderer": "^17.0.1",
"@types/seamless-immutable": "^7.1.16",
"@wolox/js-test-coverage-script": "^0.0.2",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.3",
"babel-plugin-import-glob": "^2.0.0",
"babel-plugin-module-resolver": "^4.1.0",
"eslint": "^8.2.0",
"eslint-config-airbnb": "^19.0.2",
"eslint-config-prettier": "^8.3.0",
"eslint-config-wolox-react-native": "^1.0.1",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^25.3.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.27.1",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-react-native": "^4.0.0",
"husky": "^7.0.4",
"jest": "^26.6.3",
"jest-react-native": "^18.0.0",
"metro-react-native-babel-preset": "^0.66.2",
"prettier": "^2.5.1",
"prettier-eslint": "^13.0.0",
"react-test-renderer": "17.0.2",
"redux-mock-store": "^1.5.4",
"terser-webpack-plugin": "^5.3.0",
"typescript": "^4.5.4",
"webpack": "^5.65.0"
},
"peerDependencies": {
"react": "*",
"react-native-gesture-handler": ">= 1.0.0",
"react-native-safe-area-context": ">= 3.0.0"
},
"jest": {
"preset": "react-native"
},
"husky": {
"hooks": {
"pre-commit": "yarn run lint-diff && yarn run check-types && yarn run test:coverage"
}
},
"main": "dist/module/index.js",
"module": "dist/module/index.js",
"react-native": "src/index.ts",
"types": "dist/typescript/src/index.d.ts",
"files": [
"dist/",
"src/"
],
"@react-native-community/bob": {
"source": "src",
"output": "dist",
"targets": [
["module", { "babelrc": true }],
"typescript"
]
}
}
just use .babelrc.js and it is fine. I dont know why.
In the config you have specified "babelrc": true which enables support for .babelrc. If you want to use babel.config.js, you need to specify "configFile": true
https://github.com/callstack/react-native-builder-bob#commonjs