无法解析在项目或这些目录中找不到组件:node_modules

问题描述 投票:0回答:0

我正在使用打字稿设置 React Native 项目,并且我在导入设置上苦苦挣扎了好几天,在导入我自己编写的组件时出现此错误,而不是从库中导入:

error: Error: Unable to resolve module screens/BulletinScreen from C:\Development_Projects\atlas\src\navigation\AppNavigator.tsx: screens/BulletinScreen could not be found within the project or in these directories:
  node_modules
   6 | import {NavigationContainer} from '@react-navigation/native';
   7 | import React from 'react';
>  8 | import BulletinScreen from 'screens/BulletinScreen';
     |                             ^
   9 | import StudyInfoScreen from 'screens/StudyInfoScreen';
  10 | import BottomTabBar from './components/BottomTabBar';
  11 | import screenKey from './ScreenKey';

任何帮助将不胜感激,这是我的

babel.config.js

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],

  plugins: [
    [
      'module-resolver',
      {
        root: ['./'],
        alias: {
          assets: './src/assets',
          components: './src/components',
          navigation: './src/navigation',
          redux: './src/redux',
          screens: './src/screens',
          types: './src/types',
          utils: './src/utils',
        },
      },
    ],
  ],
};

tsconfig.json

{
  "extends": "@tsconfig/react-native/tsconfig.json",
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "assets/*": ["./src/assets/*"],
      "components/*": ["./src/components/*"],
      "navigation/*": ["./src/navigation/*"],
      "redux/*": ["./src/redux/*"],
      "screens/*": ["./src/screens/*"],
      "types/*": ["./src/types/*"],
      "utils/*": ["./src/utils/*"]
    },
    "typeRoots": ["@types", "node_modules/@types"],
    "skipLibCheck": true
  },
  "include": ["./src", "App.tsx"]
}
typescript react-native babeljs tsconfig javascript-import
© www.soinside.com 2019 - 2024. All rights reserved.