svelte-store: extensionless re-exports in src/index.svelte.ts break Node ESM and nodenext types

未关闭 适合新手
#412 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@Mittalnew 已经在做这个了。

开始于 2026年11月16日。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
86/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

从 packages/svelte-store/src/index.svelte.ts 开始,将其相对再导出与生成的 dist/index.svelte.js 和 dist/index.svelte.d.ts 进行比较。为 issue 中指出的三个没有扩展名的再导出添加 .js 扩展名。完成标准是 Node ESM 导入成功,且 TypeScript 使用 node16 或 nodenext 时能解析这些导出;issue 报告称 svelte-check 仍然通过。

由索引模型根据 Issue 内容生成。

描述

Describe the bug

packages/svelte-store/src/index.svelte.ts mixes .js and extensionless relative re-exports:

export * from '@tanstack/store'

export * from './useSelector.svelte.js'

export * from './useAtom'
export * from './useStore' // @deprecated in favor of useSelector
export * from './_useStore'

Unlike the other packages in this repo (which bundle with tsdown), @tanstack/svelte-store builds with svelte-package, which copies relative specifiers unchanged into dist/index.svelte.js and dist/index.svelte.d.ts. Because @tanstack/svelte-store declares "type": "module", Node's ESM loader throws ERR_MODULE_NOT_FOUND on ./useAtom whenever @tanstack/svelte-store is loaded outside Vite's bundler (such as Node scripts, tests, or SSR with externalized dependencies), and TypeScript under moduleResolution: "node16" or "nodenext" fails to resolve useAtom, useStore, and _useStore.

Steps to Reproduce the Bug or Issue
mkdir repro && cd repro
npm init -y && npm pkg set type=module
npm i @tanstack/[email protected] svelte [email protected]
node --input-type=module -e "import('@tanstack/svelte-store').catch(e => console.log(e.code, e.message))"

Node output:

ERR_MODULE_NOT_FOUND Cannot find module '.../repro/node_modules/@tanstack/svelte-store/dist/useAtom' imported from .../repro/node_modules/@tanstack/svelte-store/dist/index.svelte.js

TypeScript (repro.mts):

import { createAtom, useAtom, useSelector, useStore, _useStore } from '@tanstack/svelte-store'
console.log(createAtom, useAtom, useSelector, useStore, _useStore)

Running npx tsc --noEmit --strict --module nodenext --moduleResolution nodenext repro.mts:

node_modules/@tanstack/svelte-store/dist/index.svelte.d.ts(3,15): error TS2835: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './useAtom.js'?
node_modules/@tanstack/svelte-store/dist/index.svelte.d.ts(4,15): error TS2835: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './useStore.js'?
node_modules/@tanstack/svelte-store/dist/index.svelte.d.ts(5,15): error TS2835: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './_useStore.js'?
repro.mts(1,22): error TS2305: Module '"@tanstack/svelte-store"' has no exported member 'useAtom'.
repro.mts(1,44): error TS2305: Module '"@tanstack/svelte-store"' has no exported member 'useStore'.
repro.mts(1,54): error TS2305: Module '"@tanstack/svelte-store"' has no exported member '_useStore'.

With --skipLibCheck, the three TS2305 errors on repro.mts still fail compilation. (--moduleResolution bundler passes.)

Expected behavior

import('@tanstack/svelte-store') loads cleanly in Node ESM, and useAtom, useStore, and _useStore resolve under node16 and nodenext just as useSelector already does.

Screenshots or Videos

N/A

Platform
  • OS: Linux x86_64
  • Runtime / Compiler: Node.js v26.13.0, TypeScript 6.0.3 and 7.0.2
  • Version: @tanstack/[email protected] (latest release; also reproduces when built from main at 0e95a97)
Additional context

Adding .js to the three re-exports in packages/svelte-store/src/index.svelte.ts ('./useAtom.js', './useStore.js', './_useStore.js') fixes both dist/index.svelte.js and dist/index.svelte.d.ts while keeping svelte-check green.

Credit: https://ucsbplse.github.io/

主要语言
TypeScript
星标
913
派生
121
平均合并
19 小时 51 分钟
30 天内合并 PR
2

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/store 的其他 Issue

查看 TanStack/store 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。