-
Notifications
You must be signed in to change notification settings - Fork 24.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Custom Path Aliases Are Not Working #45120
Comments
|
|
I am using the latest version 0.74.2, but the same problem occurs, and I used two methods to solve this problem, one was the metro.js configuration and the other was the babel configuration, but neither worked. |
can you modify
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: [
[
"module-resolver",
{
alias: {
"@": "./src"
},
},
],
],
};
{
"extends": "@react-native/typescript-config/tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
}
}
}
import { foo } from '@/foo' |
Thank you for solving my problem |
Description
The custom path alias I set according to the official website does not work.
Below is my configuration file.
tsconfig.json
{
"extends": "@react-native/typescript-config/tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"": ["src/"],
"@/": ["src/"],
"@views/": ["src/views/"],
"@components/": ["src/components/"],
"@assets/": ["src/assets/"],
"@screen/": ["src/screen/"]
}
}
}
babel.config.js
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: [
[
'module-resolver',
{
root: ['./src'],
extensions: ['.ios.js', '.android.js', 'js', 'jsx', 'ts', 'tsx'],
alias: {
'@/': './src/',
'@components': './src/components/',
'@views': './src/views/',
'@assets': './src/assets/',
'@screen': './src/screens/',
},
},
],
],
}
Steps to reproduce
npm run ios
or
npm run android
React Native Version
0.74.0
Affected Platforms
Runtime - Android, Runtime - iOS
Output of
npx react-native info
Stacktrace or Logs
Reproducer
none
Screenshots and Videos
No response
The text was updated successfully, but these errors were encountered: