使用Next.js和Typescript初始化hotjar时的问题



我使用react-hotjar version 6.0.0在Next.js和TypeScript应用程序中初始化hotjar失败。

步骤包括:

文件_app.tsx

我使用 导入它
import { hotjar } from 'react-hotjar';

然后在默认的function App中初始化,如下所示:

useEffect(() => {
hotjar.initialize(HJID, HJSV);
}, [])

然而当我运行

next build && next export

我收到以下错误:

Module parse failed: Identifier 'hotjar' has already been declared (11:13)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| ***
| 
> export const hotjar = ***
|   initialize: function initialize(id, sv) ***
|       hotjar(id, sv);
Import trace for requested module:
./node_modules/react-hotjar/index.js
> Build failed because of webpack errors

你知道失败的原因是什么吗?

或者,你能告诉我如何在TypeScript Next.js web应用程序中初始化hotjar的资源吗?

我也遇到了同样的问题。为了解决这个问题,我不得不恢复到以前的版本。目前,我使用的是v5.5.0。

最新更新