react native configuration absolute path@

react nativeTo configure the absolute path '@/...', a third-party plug-in is required:babel-plugin-module-resolver

1. Install the plug-in

目前用的版本: ^5.0.0
yarn add babel-plugin-module-resolver

2. Configurationbabel.config.js

plugins: [
    [
      'module-resolver',
      {
    
    
        root: ['./'],
        extensions: ['.ios.js', '.android.js', '.js', '.ts', '.tsx', '.json'],
        alias: {
    
    
          '@': './src/',
        },
      },
    ],
  ],

legend:
insert image description here

3. If the installation reports an error:
insert image description here

But now add in package.json first: "babel-plugin-module-resolver": "^5.0.0"
insert image description here
then execute yarn config set ignore-engines true, and then execute, yarn installas shown
in the figure below:
insert image description here

Guess you like

Origin blog.csdn.net/qq_44094296/article/details/130705513