首页 > 解决方案 > 全新安装后尝试运行本机应用程序时出错

问题描述

所以我一直在关注本教程:youtube.com/watch?v=qSRrxpdMpVc 尝试学习应用程序开发的本机反应,但我一直受到问题的困扰。使用 expo 创建项目后,使用 expo-template-blank 运行:

expo init first

然后创建这个非常简单的应用程序,就像我在教程中学到的那样:

import React, {useState} from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';

export default function App() {
  const[outputText, setOutputText] = useState('New State');
  return (
    <View style={styles.container}>
<Text>{outputText}</Text>
      <Button title="Change Text" onPress={() => setOutputText('the text changed')}/>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

我试图通过 cd 到目录测试应用程序,然后运行

yarn start

但是当我这样做时,我得到了这个巨大的错误:

    C:\www\first>yarn start
yarn run v1.21.0
warning ..\package.json: No license field
$ expo start
Starting project at C:\www\first
Expo DevTools is running at http://localhost:19002
Opening DevTools in the browser... (press shift-d to disable)
error Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class. Run CLI with --verbose flag for more details.

SyntaxError: Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class
    at new RegExp (<anonymous>)
    at blacklist (C:\www\first\node_modules\metro-config\src\defaults\blacklist.js:34:10)
    at getBlacklistRE (C:\www\first\node_modules\@react-native-community\cli\build\tools\loadMetroConfig.js:66:59)
    at getDefaultConfig (C:\www\first\node_modules\@react-native-community\cli\build\tools\loadMetroConfig.js:82:20)
    at load (C:\www\first\node_modules\@react-native-community\cli\build\tools\loadMetroConfig.js:118:25)
    at Object.runServer [as func] (C:\www\first\node_modules\@react-native-community\cli\build\commands\server\runServer.js:82:58)
    at Command.handleAction (C:\www\first\node_modules\@react-native-community\cli\build\index.js:164:23)
    at Command.listener (C:\www\first\node_modules\commander\index.js:315:8)
    at Command.emit (events.js:210:5)
    at Command.parseArgs (C:\www\first\node_modules\commander\index.js:651:12)
Metro Bundler process exited with code 1
Set EXPO_DEBUG=true in your env to view the stack trace.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

有谁知道这可能是什么原因造成的?我对 React 感到非常沮丧,因为刚开始安装 React 是一件很麻烦的错误,现在我什至无法测试一个非常简单的应用程序。感谢您的帮助,在此先感谢!

标签: reactjsreact-nativewebexpo

解决方案


推荐阅读