【问题标题】:I cant install react native我无法安装本机反应
【发布时间】:2021-11-14 17:32:24
【问题描述】:

我该如何解决这个问题? 当我在 react native 中安装一些东西时,VC 代码显示错误,这是一个大问题吗?

pm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2freact-native-simple-alarm - Not found
npm ERR! 404
npm ERR! 404  '@types/react-native-simple-alarm@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User\AppData\Roaming\npm-cache\_logs\2021-09-21T05_47_59_621Z-debug.log

【问题讨论】:

    标签: node.js react-native npm


    【解决方案1】:

    TypeScript 定义包

    您要安装的是一个 TypeScript Definition 包,因为它有一个 @types 前缀。不幸的是,这个包don't exist 的 TypeScript 定义,这就是 npm install 命令抛出错误的原因。

    如何检查一个包是否存在 TypeScript 定义?

    这很简单。只需检查 NPM 中包名称旁边的 Dt 徽标,此处为 react

    点击哪个,它会带你到包的 TypeScript Definitions 包,这里是@types/react

    【讨论】:

      【解决方案2】:

      从该错误看来,您正在安装 Typescript 声明文件。

      @types 前缀是 Typescript 的专用类型,它是 Typescript 声明文件的存储库(您可以在 DefinedTyped 中阅读更多内容)。

      如果您使用 typescript 编译您的 react-native 代码,那么您应该担心,如果您使用的库不支持开箱即用的 typescript,您会看到很多编译问题。你可以选择编写一个专门的 d.ts 来支持它,或者如果你很好,你可以贡献给 @types/ 以便其他人可以使用。 :)

      简单地说,react-native-simple-alarm 在@types 中似乎没有专门的文件,从源代码来看,它也不支持自己的打字稿。如果你跑了

      npm install @types/react-native-simple-alarm
      

      您将收到异常,因为 @types 中不存在该库。

      如果你只是使用普通的 javascript,下面的命令就足够了。

      npm install react-native-simple-alarm //or yarn
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-23
        • 1970-01-01
        • 2020-04-11
        • 2021-12-10
        • 1970-01-01
        相关资源
        最近更新 更多