react native
To 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:
3. If the installation reports an error:
But now add in package.json first: "babel-plugin-module-resolver": "^5.0.0"
then execute yarn config set ignore-engines true
, and then execute, yarn install
as shown
in the figure below: