reactjs - “ExoticComponent”类型上不存在属性 ***
问题描述
我尝试在 React / Next.js 项目中进行代码拆分,但面临障碍。
我在这里遵循操作方法:https ://reactjs.org/docs/code-splitting.html
在这里导入:
const { SHA512 } = React.lazy(() => import("crypto-js"));
并在useEffect
这里使用:
useEffect(() => {
setTimeout(() => {
let window2: any = window;
if (window2.bp && process.env.NEXT_PUBLIC_BARION_ID) {
const { totalPriceInt, unitPriceInt } = calcUnitAndTotalPrice(
startPaymentIn,
buyTicketData
);
window2.bp("track", "initiateCheckout", {
contentType: "Product",
currency: "HUF",
id: startPaymentIn.eventId,
name: buyTicketData?.name,
quantity: startPaymentIn.quantity ?? 1.0,
unit: "db",
imageUrl: `https://ticket-t01.s3.eu-central-1.amazonaws.com/${buyTicketData?.imgId}_0.cover.jpg`,
list: "ProductPage",
});
window2.bp("track", "setUserProperties", {
userId: SHA512(getTempUserId(localStorage)).toString(), // <--- HERE
});
}
}, 4000);
}, []);
但得到这个错误:
./components/LoginAndRegistration.tsx:25:9
Type error: Property 'SHA512' does not exist on type 'ExoticComponent<any> & { readonly _result: ComponentType<any>; }'.
23 | import { GoogleLogin } from "react-google-login";
24 | import axios from "axios";
> 25 | const { SHA512 } = React.lazy(() => import("crypto-js"));
| ^
26 |
27 | interface LoginAndRegistrationProps {
28 | isRegistration: boolean;
error Command failed with exit code 1.
你知道为什么它是错的吗?
在没有延迟加载的情况下工作之前:
import { SHA512 } from "crypto-js";
我还尝试了 Next.js 解决方法:
import dynamic from "next/dynamic";
const { SHA512 } = dynamic(() => import("crypto-js"));
但收到此错误:
Type error: 'await' expressions are only allowed within async functions and at the top levels of modules.
130 |
131 | useEffect(() => {
> 132 | const { SHA512 } = await import("crypto-js");
| ^
133 | setTimeout(() => {
134 | let window2: any = window;
135 | if (window2.bp && process.env.NEXT_PUBLIC_BARION_ID) {
解决方案
推荐阅读
- talend - 如何在 Talend 中从一行中创建多行?
- selenium - InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression contains(text() error message
- sql - SQL中表的语法不正确
- gradle - Gradle - compileClasspath 和 runtimeClassPath 中的不同库版本
- python - 从字符串末尾(而不是中间)删除标点符号
- javascript - 在 JavaScript 中处理 HTTP 请求
- azure-data-factory-2 - Azure 数据工厂动态检查文件名
- r - 更改函数参数名称会破坏函数
- python - 连接两个列表的笛卡尔积中的字符串(最好没有 for 循环)
- python - 最近使用了一个使用 Ngrok 的旧脚本,但现在它不起作用