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

使用Tsup打包React库支持服务端组件时遇内存溢出问题求助

打包React开源UI库支持服务端组件时的Tsup内存溢出问题

我在用Tsup打包React开源UI库以支持服务端组件时遇到了问题:原配置将所有内容打包为单个文件,导致需要作为服务端组件加载的组件出现冲突。我尝试单独打包每个组件,通过桶形索引文件聚合,仅在必要组件上添加'use client'指令,但新配置触发了ERR_WORKER_OUT_OF_MEMORY错误。

我正在开发这款开源UI库,目标是让它默认无缝支持'use client'指令,欢迎帮忙解决问题或提供打包配置优化建议。

原Tsup配置

import { defineConfig } from 'tsup'

export default defineConfig((option) => ({
 entry: ['src/index.ts'],
 format: ['cjs', 'esm'],
 splitting: false,
 sourcemap: true,
 clean: true,
 dts: true,
 treeshake: true,
 external: ['react', 'react-dom'],
 minify: !option.watch,
}))

新Tsup配置

import { defineConfig } from 'tsup'

export default defineConfig({
 sourcemap: true,
 entry: ['./src/index.ts', './src/core/**/index.tsx'],
 format: ['cjs', 'esm'],
 splitting: false,
 outDir: 'dist/',
 dts: true,
 minify: true,
 treeshake: true,
 external: ['react', 'react-dom'],
 bundle: false,
 esbuildOptions(options, context) {
   options.outbase = './'
 },
})

错误信息

@pillar-ui/core:dev: Error [ERR_WORKER_OUT_OF_MEMORY]: Worker terminated due to reaching memory limit: JS heap out of memory

目标

  • 单独打包每个组件
  • 为需要的组件添加"use client"指令

内容的提问来源于stack exchange,提问作者Hamza Miloud Amar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 04:57:17