欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

解决初始化TypeScript模板的RN项目报错问题

程序员文章站 2022-06-15 22:46:09
...
info Fetching template react-native-template-react-native-template-typescript...
yarn add v1.22.4
warning ../../../package.json: No license field
[1/4] ????  Resolving packages...
warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > [email protected]: use String.prototype.padStart()
warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
error An unexpected error occurred: "https://registry.npm.taobao.org/react-native-template-react-native-template-typescript: ETIMEDOUT".
info If you think this is a bug, please open a bug report with the information provided in "/Users/*nsheng/Desktop/rn-works/RN_WanAndroid/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
yarn remove v1.22.4
warning ../../../package.json: No license field
[1/2] ????  Removing module react-native-template-react-native-template-typescript...
error This module isn't specified in a package.json file.
info Visit https://yarnpkg.com/en/docs/cli/remove for documentation about this command.
warn Failed to clean up template temp files in node_modules/react-native-template-react-native-template-typescript. This is not a critical error, you can work on your app.
(node:55771) UnhandledPromiseRejectionWarning: Error: Command failed: yarn add react-native-template-react-native-template-typescript
    at makeError (/Users/*nsheng/Desktop/rn-works/RN_WanAndroid/node_modules/execa/index.js:174:9)
    at /Users/*nsheng/Desktop/rn-works/RN_WanAndroid/node_modules/execa/index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
(node:55771) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:55771) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

解决方式:

1.删除旧版本 react-native-cli

npm uninstall -g react-native-cli

2.重新安装来自"react-native-community"的cli库 :

npm i -g @react-native-community/cli

3.重新初始化项目即可:

npx react-native init MyApp --template react-native-template-typescript