javascript - 模块“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,
}
}
这可能是一个重复的问题。但是我不知道如何解决这个问题,有人可以帮我解决这个问题吗?
解决方案
删除当前的node_modules文件夹和package-lock.json文件。然后运行命令后,
npm cache clean --force
然后再次安装所有 npm 包
npm i
如果你可以保留 -> "skipLibCheck": true 在 tsconfig.json 中会更好。将有助于进一步解决这个问题。
然后尝试再次构建项目。希望问题能得到解决。
推荐阅读
- java - 为什么 List.contains(Object) 的行为不同?
- r - 如何在同一个数据帧上做colsum和average
- powerbi - 使用 DAX 生成日期系列
- javascript - 仅在服务器上需要一个包
- java - Intellij IDEA 仅针对所有未提交的更改运行测试
- regex - 在换行符之前匹配字符,不包括空格?
- macos - MacOS - 使用带有launchd的脚本 - 启动,登录,注销,关闭?
- service-worker - Workbox 的服务人员在更改时未更新
- python - AllenNLP 共指分辨率的多 GPU 训练
- reactjs - 事件处理程序中带有 [name] 的 PrevState