我已通过以下方式将 axe-core/react 添加到我的项目中:
npm install --save-dev @axe-core/react
Run Code Online (Sandbox Code Playgroud)
现在,我在 index.tsx 中添加了以下代码以使其启动并运行:
if (process.env.NODE_ENV !== 'production') {
const axe = require('@axe-core/react');
axe(React, ReactDOM, 1000);
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我导航到本地主机,该页面会显示编译错误,并显示以下消息:
src\index.tsx
第 14:17 行:Require 语句不是 import 语句的一部分
@typescript-eslint/no-var-requires
此错误发生在以下行:
const axe = require('@axe-core/react');
Run Code Online (Sandbox Code Playgroud)
否则我该如何导入它?
PS:我尝试做类似的事情:
import foo = require("foo")
Run Code Online (Sandbox Code Playgroud)
但仍然没有运气。