简体   繁体   English

Cloudinary-React 找不到模块“cloudinary-react”的声明文件 - 不使用 TypeScript

[英]Cloudinary-React Could not find a declaration file for module 'cloudinary-react' - Not using TypeScript

I am trying to import { Image } from "cloudinary-react";我正在尝试import { Image } from "cloudinary-react"; As instructed at Cloudinary-React按照Cloudinary-React 的指示

And getting the warning:并收到警告:

Could not find a declaration file for module 'cloudinary-react'.找不到模块“cloudinary-react”的声明文件。 '/Users/myname/Web Projects/ProjectName/node_modules/cloudinary-react/dist/cloudinary-react.js' implicitly has an 'any' type. '/Users/myname/Web Projects/ProjectName/node_modules/cloudinary-react/dist/cloudinary-react.js' 隐含了一个 'any' 类型。 Try npm i --save-dev @types/cloudinary-react if it exists or add a new declaration (.d.ts) file containing declare module 'cloudinary-react';如果存在,请尝试npm i --save-dev @types/cloudinary-react或添加包含declare module 'cloudinary-react'; ts(7016) ts(7016)

I am not using TypeScript .我没有使用 TypeScript

I can not figure out what is going on.我不知道发生了什么。 Does anyone have any ideas how I can resolve this?有谁知道我该如何解决这个问题? I have looked around for a few hours.我已经环顾了几个小时。

Package.json: "dependencies": { "axios": "^0.21.1", "bcrypt": "^5.0.0", "cloudinary": "^1.27.1", "cloudinary-react": "^1.7.0", ... Package.json: "dependencies": { "axios": "^0.21.1", "bcrypt": "^5.0.0", "cloudinary": "^1.27.1", "cloudinary-react": "^1.7.0", ...

Thank you for any help.感谢您的任何帮助。

The cloudinary-react module should normally be added in the node_modules when it is installed in your project. cloudinary-react 模块通常应在安装到项目中时添加到node_modules中。 The following sample code is shown in this sample project .示例项目中显示了以下示例代码。

For the dependencies in package.json:对于 package.json 中的依赖项:

"dependencies": {
    "cloudinary-react": "1.7.0",
    "lodash": "4.17.21",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-scripts": "4.0.0"
},

And Cloudinary components can be imported as shown below:并且可以导入 Cloudinary 组件,如下所示:

import React from "react";

import { Image } from "cloudinary-react";

class ImageDisplay extends React.Component {
  render() {
    return (
      <div className="counter">
        <Image cloudName="demo" publicId="sample" width="300" crop="scale" />
      </div>
    );
  }
}

export default ImageDisplay;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM