reactjs - 如何解决这个 MERN stack filebase64 错误?

标签 reactjs mongodb typescript mern react-fullstack

import FileBase from 'react-file-base64';

将三点指示器悬停在 VS Code 中后出现错误。

除了插入图像的 filebase64 部分之外,我的设置已经成功(其他输入字段已成功插入到 MongoDB 云中)。

module "d:/nodejs/memories_project/client/node_modules/react-file-base64/build/build.min" Could not find a declaration file for module 'react-file-base64'. 'd:/nodejs/memories_project/client/node_modules/react-file-base64/build/build.min.js' implicitly has an 'any' type. Try npm i --save-dev @types/react-file-base64 if it exists or add a new declaration (.d.ts) file containing declare module 'react-file-base64';ts(7016)

这是我的package.json的依赖项:

"dependencies": {
    "@material-ui/core": "^4.9.10",
    "@material-ui/icons": "^4.9.1",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "axios": "^0.19.2",
    "moment": "^2.27.0",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-file-base64": "^1.0.3",
    "react-redux": "^7.1.3",
    "react-scripts": "3.4.1",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0"
  },

最佳答案

如果该值未保存在数据库中,则意味着该值为空或不存在。检查模型文件(/server/models/)中的字段名称是否与表单文件(/client/src/components/)中的字段名称相同。

现在错误消息与实际问题无关。

发生这种情况是因为react-file-base64不提供任何类型。要消除错误,您需要在 .d.ts 文件中声明该模块。

为此,请使用以下代码在项目根目录(package.json 所在位置)中创建一个 .d.ts 文件(例如 index.d.ts):

declare module 'react-file-base64';

或者你可以声明所有

declare module '*';

关于reactjs - 如何解决这个 MERN stack filebase64 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66258644/

相关文章:

json - MongoDB - 动态更新嵌套数组中的对象

mysql - 使用 MongoDB 和 Yii2 高级模板创建简单查询

javascript - 使用 parseInt 转换单选按钮会返回一个字符串

java - ReactJS 和 Java : Response to preflight request doesn't pass access control check

reactjs - React Router v4 的嵌套路由不起作用

reactjs - 如何在没有 npm start 或类似命令的情况下在 HTML 中使用 React 应用程序

node.js - 如何使用 npm 安装所有要求?

mongodb - elasticsearch:从mongodb重新同步索引

Angular 2 : Dynamic load component Error

postgresql - 在 typeORM Typescript 中的 WHERE 条件中使用 LIKE