问题描述
我已通过以下方式将 axe-core/react 添加到我的项目中:
npm install --save-dev @axe-core/react
现在我在我的 index.tsx 中添加了以下代码来启动和运行:
if (process.env.NODE_ENV !== 'production') {
const axe = require('@axe-core/react');
axe(React,ReactDOM,1000);
}
现在,如果我导航到 localhost,页面会显示 compile error 并显示以下消息:
src\index.tsx
Line 14:17: Require statement not part of import statement @typescript-eslint/no-var-requires
此行发生此错误:
const axe = require('@axe-core/react');
否则我如何导入它?
PS:我尝试做类似的事情:
import foo = require("foo")
但仍然没有运气。
解决方法
换行
const axe = require('@axe-core/react');
与
import axe from '@axe-core/react';
解决了我的问题。