Closed 814704261 closed 1 day ago
:warning: | Newer Version of React Native is Available! |
---|---|
:information_source: | You are on a supported minor version, but it looks like there's a newer patch available - 0.74.2. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases. |
:warning: | Missing Reproducible Example |
---|---|
:information_source: | We could not detect a reproducible example in your issue report. Please provide either:
|
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 babel.config.js
without trailiing /
. below config works for me on rn 0.74.3 and metro 0.80.9
babel.config.js
module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: [
[
"module-resolver",
{
alias: {
"@": "./src"
},
},
],
],
};
tsconfig.json
{
"extends": "@react-native/typescript-config/tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
}
}
}
App.tsx
import { foo } from '@/foo'
can you modify
babel.config.js
without trailiing/
. below config works for me on rn 0.74.3 and metro 0.80.9
babel.config.js
module.exports = { presets: ['module:@react-native/babel-preset'], plugins: [ [ "module-resolver", { alias: { "@": "./src" }, }, ], ], };
tsconfig.json
{ "extends": "@react-native/typescript-config/tsconfig.json", "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./src/*"], } } }
App.tsx
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