You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何出现‘direction不存在于LenisOptions类型’的TypeScript错误?

问题解答

这个TypeScript错误的核心原因是:你当前使用的@studio-freight/lenis版本中,LenisOptions类型定义已经移除了direction配置项——该属性在Lenis的v1及以上版本里被废弃,因为组件默认就是垂直滚动模式,无需额外声明。

解决步骤:

直接从Lenis的初始化参数中删除direction: "vertical"这一行即可,修改后的代码如下:

"use client";

import { ReactNode, useEffect } from "react";
import Lenis from "@studio-freight/lenis";

export default function SmoothScroll({ children }: { children: ReactNode }) {
  useEffect(() => {
    const lenis = new Lenis({
      duration: 1.2,
      easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
      smooth: true,
      smoothTouch: false,
      touchMultiplier: 2,
    });

    function raf(time: number) {
      lenis.raf(time);
      requestAnimationFrame(raf);
    }

    requestAnimationFrame(raf);

    return () => {
      lenis.destroy();
    };
  }, []);

  return <>{children}</>;
}

如果你的需求是实现水平滚动,新版本的Lenis不需要通过direction配置,只需给目标滚动容器设置CSS属性overflow-x: auto并确保容器有足够的宽度,Lenis会自动适配滚动方向。

内容的提问来源于stack exchange,提问作者Tasfiq.Asif

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 13:52:03