error TS2742: The inferred type of 'default' cannot be named without a reference
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- rollup, typescript
- 领域
- build-system, tooling
调研方向
先从 src/runtime/plugin.ts 和 playground/app.config.ts 中的复现开始,然后检查 playground/node_modules/myPackage/dist 下生成的声明。运行 pnpm prepack 以复现 TS2742,并将失败的声明与使用 Params = string; 的变体进行比较;当模块能够在没有不可移植的推断类型错误的情况下构建时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Im trying to pnpm prepack a nuxt3 module with a package which exports a simple object and its types file.
1 - In the playground/node_modules/myPackage/dist
index.d.ts :
type Params = string[];
declare const endpoints: {
abc: (q: Params) => string;
};
export { Params, endpoints as default };
index.js :
// src/index.ts
var endpoints = {
abc: (q) => "test"
};
var src_default = endpoints;
export {
src_default as default
};
2 - In the playground/app.config.ts
import endpoints from "myPackage";
export default {
endpoints
};
3 - In the module, src/runtime/plugin.ts :
import { defineNuxtPlugin, useAppConfig } from "#imports";
export default defineNuxtPlugin(() => {
return {
provide: {
backend: useAppConfig().endpoints,
},
};
});
Then, i run pnpm prepack and i always have this error :
ℹ Building my-module 12:16:16 PM
src/runtime/plugin.ts(3,1): error TS2742: The inferred type of 'default' cannot be named without a reference to '../../playground/node_modules/@aurionsarl/auberdog-pension-api/dist'. This is likely not portable. A type annotation is necessary.
src/runtime/plugin.ts(3,1): error TS2742: The inferred type of 'default' cannot be named without a reference to '../../playground/node_modules/@aurionsarl/auberdog-pension-api/dist'. This is likely not portable. A type annotation is necessary.
Error [RollupError]: Failed to compile. Check the logs above.
at error (file:///home/tony/projects/testmodule/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:2245:30)
at Object.error (file:///home/tony/projects/testmodule/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:25139:20)
at Object.error (file:///home/tony/projects/testmodule/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:24262:42)
at generateDtsFromTs (file:///home/tony/projects/testmodule/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.mjs:1697:30)
at Object.transform (file:///home/tony/projects/testmodule/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.mjs:1706:38)
at file:///home/tony/projects/testmodule/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:25332:40
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
id: '/home/tony/projects/testmodule/src/module.ts',
hook: 'resolveId',
code: 'PLUGIN_ERROR',
plugin: 'commonjs--resolver',
watchFiles: [
'/home/tony/projects/testmodule/src/module.ts',
'/home/tony/projects/testmodule/src/runtime/plugin.ts'
]
}
ELIFECYCLE Command failed with exit code 1.
And the error disappears if i replace the code in the playground/node_modules/myPackage/dist by this one :
type Params = string; // replace string[] to string
declare const endpoints: {
abc: (q: Params) => string;
};
export { Params, endpoints as default };
- 主要语言
- TypeScript
- 星标
- 277
- 派生
- 36
- 平均合并
- 2 小时 46 分钟
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nuxt/module-builder 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 68/100
nuxt/module-builder#801 ·
-
enhancement
难度 3/5 1-2 天 新手友好度 48/100
nuxt/module-builder#764 ·
-
难度 3/5 1-2 天 新手友好度 45/100
nuxt/module-builder#754 ·
-
Conflict between folder structure in readme (src/runtime) and TypeScript config (src/module/runtime)可能已有人在做 @dword-design 于 137 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 45/100
nuxt/module-builder#749 ·
-
Tsdown/obuild migration可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 5/5 一周以上 新手友好度 25/100
nuxt/module-builder#726 · 1 条评论 · 1 个 reaction ·
查看 nuxt/module-builder 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
jessepollak/home#2223 ·
维护者通常 1 天内回复
-
grep fixture corpus test follows the corpus's loop symlink under the receipt runner (fails on main)未关闭
难度 2/5 1-3 小时 新手友好度 68/100
code-yeongyu/senpi#3756 ·
维护者通常 1 天内回复
-
org:external package:deepagents priority:triage topic:memory topic:middleware type:bug
难度 2/5 1-3 小时 新手友好度 65/100
langchain-ai/deepagents#7059 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 92/100
osmlab/name-suggestion-index#12992 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
hemilabs/ui-monorepo#2506 ·
维护者通常 1 天内回复