Expo构建错误 - ENOENT:没有这个文件或目录,扫描'\src\screens\node_modules\native-base\Fonts'。

3
我在将Expo SDK版本升级到33后遇到了这个错误:
ENOENT: no such file or directory, scandir '.\node_modules\native-base\Fonts'
Failed building JavaScript bundle.
2个回答

1
更新Expo可能会导致与更新的@expo/vector-icons发生冲突。如果删除了native-base模块且未重新安装,或问题未得到解决,可能会出现问题。
rm -rf node_modules && yarn install && expo start

该死,这个可用。 - Abhishek Thapliyal

1

Expo以一种新的方式加载字体:

https://docs.expo.io/versions/latest/sdk/font/

以下示例基于native-base和expo文档中的示例。

https://github.com/GeekyAnts/NativeBase

你可能需要先运行这个:
expo install expo-font

然后,在你的代码中:

import * as Font from 'expo-font'

并且

export default class App extends React.Component {
  async componentDidMount() {
    await Font.loadAsync({
      'open-sans-bold': require('./assets/fonts/OpenSans-Bold.ttf'),
    });
    this.setState({ isReady: true });
  }

  // ...
}

使用native-base/Fonts/Roboto.ttf的导入路径对我没有起作用,但是使用以下类似的相对路径可以解决问题:
await Font.loadAsync({
    Roboto: require('../node_modules/native-base/Fonts/Roboto.ttf'),
    Roboto_medium: require('../node_modules/native-base/Fonts/Roboto_medium.ttf')
});

这里是一个稍微更完整的例子:

export default class extends React.Component {
    state = {
        isReady: false,
    };
    async componentDidMount() {
        await Font.loadAsync({
            Roboto: require('../node_modules/native-base/Fonts/Roboto.ttf'),
            Roboto_medium: require('../node_modules/native-base/Fonts/Roboto_medium.ttf')
        });
        this.setState({ isReady: true });
    }
    render() {
        if (!this.state.isReady) {
            return ( <AppLoading />);
        }
        return <Navigator />;
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接