无法解析模块nanoid/ nonsecure node_mo@react- navigationcore|src



输入图片描述

如您所见,文件可用。我不知道为什么会出现这个错误。错误提示在文件夹中找不到这个文件,但它显然在那里

import { nanoid } from 'nanoid/non-secure';
import * as React from 'react';
import { SingleNavigatorContext } from './EnsureSingleNavigator';
/**
* Register a navigator in the parent context (either a navigation container or a screen).
* This is used to prevent multiple navigators under a single container or screen.
*/
export default function useRegisterNavigator() {
const [key] = React.useState(() => nanoid());
const container = React.useContext(SingleNavigatorContext);
if (container === undefined) {
throw new Error(
"Couldn't register the navigator. Have you wrapped your app with 'NavigationContainer'?nnThis can also happen if there are multiple copies of '@react-navigation' packages installed."
);
}
React.useEffect(() => {
const { register, unregister } = container;
register(key);
return () => unregister(key);
}, [container, key]);
return key;
}

这是我的依赖项列表

"dependencies": {
"@expo/vector-icons": "^12.0.5",
"expo": "~44.0.0",
"expo-app-loading": "^1.3.0",
"expo-font": "^10.0.5",
"expo-status-bar": "~1.2.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-reanimated": "~2.3.1",
"react-native-web": "0.17.1",
"react-navigation": "^3.0.0",
"react-navigation-header-buttons": "^8.0.0",
"react-redux": "^7.2.8",
"redux": "^4.1.2",
"redux-devtools-extension": "^2.13.9"
},

我也遇到了同样的问题。我刚意识到我改变了babel.config.js

的预设文件。默认情况下是presets: ['babel-preset-expo'],我把它改成了presets: ['module:metro-react-native-babel-preset'],

试试其中一个。第一个对我有效。

相关内容

  • 没有找到相关文章