typescript - 使用 React Native 和 typescript 创建应用程序
问题描述
我正在尝试使用 React Native 和 TypeScript 创建一个应用程序,但它不起作用。我使用以下命令:
npx react-native init MyApp --template react-native-template-typescript
和日志错误:
Yarn version:
1.22.15
Node version:
16.10.0
Platform:
win32 x64
Trace:
Error: https://registry.yarnpkg.com/react-native-template-react-native-template-typescript: Not found
at Request.params.callback [as _callback] (C:\Users\pc\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:66140:18)
at Request.self.callback (C:\Users\pc\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:140885:22)
at Request.emit (node:events:390:28)
at Request.<anonymous> (C:\Users\pc\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:141857:10)
at Request.emit (node:events:390:28)
at IncomingMessage.<anonymous> (C:\Users\pc\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:141779:12)
at Object.onceWrapper (node:events:509:28)
at IncomingMessage.emit (node:events:402:35)
at endReadableNT (node:internal/streams/readable:1343:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
解决方案
您应该首先卸载以前的 react-native-cli 以安装具有 typescript 功能的最新版本。
1- npm 卸载 -g react-native-cli。
2-纱线全局添加@react-native-community/cli
3- react-native init MyApp --template react-native-template-typescript
推荐阅读
- vba - 用于检查字符串是否具有“[”、“]”字符的 VBA 访问代码
- ios - 在我的帐户上签名应用程序不起作用,但它适用于我的同事帐户
- xquery - 用于复杂负载的 Xquery
- json - PWA 调试 chrome “添加到主屏幕”按钮没有做任何事情
- api - 使用 Sitefinity 11 Rest API 返回 Draft 动态内容
- ios - 将子 UIViewConroller 添加到 UITabBarController
- c++ - 将目标文件链接到可执行文件不起作用
- javascript - 使用 WebdriverIO 关闭 firefox 更新弹出窗口
- php - 一个字母更改的奇怪的 PHP 致命错误
- python - 需要从一系列值中添加一些列表元素