npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@versa_ai/vmml-timeline

v1.4.78

Published

如果在 NextJS 项目中使用时遇到 `Module not found: Can't resolve '../build/Release/canvas.node'` 错误,请配置 `next.config.js`:

Readme

@versa_ai/vmml-timeline

NextJS 使用配置

如果在 NextJS 项目中使用时遇到 Module not found: Can't resolve '../build/Release/canvas.node' 错误,请配置 next.config.js

方案1: 动态导入(推荐)

在你的组件中使用动态导入,避免SSR问题:

import dynamic from 'next/dynamic';

// 动态导入timeline组件,禁用SSR
const VmmlTimeline = dynamic(
  () => import('@versa_ai/vmml-timeline').then((mod) => mod.VmmlTimeline),
  { 
    ssr: false,
    loading: () => <div>Loading timeline...</div>
  }
);

export default function MyPage() {
  return (
    <div>
      <VmmlTimeline 
        vmml={vmmlData}
        // ... 其他props
      />
    </div>
  );
}

方案2: Webpack配置

// next.config.js
module.exports = {
  webpack: (config, { isServer }) => {
    if (isServer) {
      // 服务端排除 fabric,避免canvas.node错误
      config.externals = config.externals || [];
      config.externals.push('fabric');
    }

    return config;
  }
};

重要提醒:如果使用方案2,建议同时使用动态导入来避免hydration错误。

方案3: 完整解决方案(如果上面都不行)

// next.config.js
const webpack = require('webpack');

module.exports = {
  webpack: (config, { isServer }) => {
    if (isServer) {
      config.externals = config.externals || [];
      config.externals.push('fabric');
    } else {
      config.resolve.fallback = {
        ...config.resolve.fallback,
        fs: false,
        encoding: false
      };
    }

    return config;
  }
};

安装依赖:

npm install fabric
# 或
pnpm add fabric

NextJS 使用示例(解决SSR问题)

import { useRef, useState, useEffect } from "react";
import dynamic from "next/dynamic";

const VmmlTimeline = dynamic(
  () => import('@versa_ai/vmml-timeline').then((mod) => mod.VmmlTimeline),
  { 
    ssr: false,
    loading: () => <div>Loading timeline...</div>
  }
);

const Player = ({ vmml }) => {
  const [vmmlData, setVmmlData] = useState(null);
  const [editableArray, setEditableArray] = useState([]);
  const [isMounted, setIsMounted] = useState(false);
  const timelineRef = useRef(null);

  // 确保组件只在客户端渲染
  useEffect(() => {
    setIsMounted(true);
  }, []);

  useEffect(() => {
    if (!vmml || !isMounted) return;
    
    // 处理vmml数据
    const processedData = JSON.parse(JSON.stringify(vmml));
    // ... 你的数据处理逻辑
    setVmmlData(processedData);
  }, [vmml, isMounted]);

  useEffect(() => {
    if (vmmlData && isMounted) {
      // 提取可编辑的元素ID
      const arr = [];
      const animateVmml = vmmlData.template.tracks.filter(item => item.type !== 0);
      animateVmml.forEach(trackItem => {
        trackItem.clips?.forEach(clipItem => {
          arr.push(clipItem.id);
        });
      });
      setEditableArray(arr);
    }
  }, [vmmlData, isMounted]);

  // 只在客户端且数据准备好后才渲染
  if (!isMounted || !vmmlData) {
    return <div>Loading...</div>;
  }

  return (
    <div className="player_wrapper">
      <VmmlTimeline
        ref={timelineRef} 
        vmml={vmmlData}
        editableArray={editableArray}
        pauseWhenBuffering
        rsaData={{}}
        switchConfig={{ AI_COMPONENT: false, TEXT_RSA: false }}
        onTimelineReady={() => {
          console.log('Timeline is ready');
        }}
      />
    </div>
  );
};

export default Player;

如果上面的方法还不行,使用这个更安全的版本:

import { useRef, useState, useEffect } from "react";
import dynamic from "next/dynamic";

const VmmlTimeline = dynamic(
  () => import('@versa_ai/vmml-timeline').then((mod) => mod.VmmlTimeline),
  { 
    ssr: false,
    loading: () => <div>Loading timeline...</div>
  }
);

const Player = ({ vmml }) => {
  const [vmmlData, setVmmlData] = useState(null);
  const [editableArray, setEditableArray] = useState([]);
  const [canRender, setCanRender] = useState(false);
  const timelineRef = useRef(null);

  useEffect(() => {
    // 确保window对象存在且DOM已加载
    if (typeof window !== 'undefined') {
      const timer = setTimeout(() => {
        setCanRender(true);
      }, 100); // 添加小延迟确保DOM完全准备好
      
      return () => clearTimeout(timer);
    }
  }, []);

  useEffect(() => {
    if (!vmml || !canRender) return;
    
    const processedData = JSON.parse(JSON.stringify(vmml));
    // ... 你的数据处理逻辑
    setVmmlData(processedData);
  }, [vmml, canRender]);

  useEffect(() => {
    if (vmmlData && canRender) {
      const arr = [];
      const animateVmml = vmmlData.template.tracks.filter(item => item.type !== 0);
      animateVmml.forEach(trackItem => {
        trackItem.clips?.forEach(clipItem => {
          arr.push(clipItem.id);
        });
      });
      setEditableArray(arr);
    }
  }, [vmmlData, canRender]);

  if (!canRender || !vmmlData) {
    return (
      <div style={{ padding: '20px', textAlign: 'center' }}>
        Loading timeline...
      </div>
    );
  }

  return (
    <div className="player_wrapper">
      <VmmlTimeline
        ref={timelineRef} 
        vmml={vmmlData}
        editableArray={editableArray}
        pauseWhenBuffering
        rsaData={{}}
        switchConfig={{ AI_COMPONENT: false, TEXT_RSA: false }}
        onTimelineReady={() => {
          console.log('Timeline is ready');
        }}
      />
    </div>
  );
};

export default Player;