首页 > 解决方案 > 模块“domhandler”没有导出成员“DomElement”。您的意思是改用“从“domhandler”导入 DomElement”吗?

问题描述

我试图建立一个反应打字稿项目。ii 没有安装 dom utils 和 HTML 解析器库。但是当我尝试运行 yarn build 时,出现以下错误

       ~~~~~~~~~~

../node_modules/@types/htmlparser2/index.d.ts:17:10 - error TS2614: Module '"domhandler"' has no exported member 'DomElement'. Did you mean to use 'import DomElement from "domhandler"' instead?

17 export { DomElement, DomHandlerOptions, DomHandler, Element, Node } from 'domhandler';
            ~~~~~~~~~~

../node_modules/@types/react-html-parser/index.d.ts:9:10 - error TS2305: Module '"htmlparser2"' has no exported member 'DomElement'.

9 import { DomElement } from "htmlparser2";

我尝试了以下一些步骤,

在 tsconfig.json 文件中添加了“skipLibCheck”:true

https://github.com/apostrophecms/sanitize-html/issues/333无论他们说什么,我都尝试了一些步骤,但仍然没有用。

tsconfig.json 文件

{
  /* https://www.typescriptlang.org/docs/handbook/react-&-webpack.html */
  /* https://www.typescriptlang.org/docs/handbook/compiler-options.html */
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs" /* webpack supports imports syntax */,
    "jsx": "react",
    "lib": ["es5", "dom", "es2015"],
    "strict": true,
    "moduleResolution": "node" /* load modules like node */,
    "esModuleInterop": true /* to treat commonJS 'module.exports' as 'default export' */,
    "importHelpers": true,
    "skipLibCheck": true,
  }
}

这可能是一个重复的问题。但是我不知道如何解决这个问题,有人可以帮我解决这个问题吗?

标签: javascriptnode.jsreactjstypescriptreact-typescript

解决方案


删除当前的node_modules文件夹和package-lock.json文件。然后运行命令后,

npm cache clean --force

然后再次安装所有 npm 包

npm i

如果你可以保留 -> "skipLibCheck": true 在 tsconfig.json 中会更好。将有助于进一步解决这个问题。

然后尝试再次构建项目。希望问题能得到解决。


推荐阅读