Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: 通过create-umi构建的Umi Plugin工程build时生成d.ts文件失败 #746

Open
kukushouhou opened this issue Mar 15, 2024 · 4 comments

Comments

@kukushouhou
Copy link

Version

4.4.0

OS Version

Windows 11 23H2

Node.js Version

v18.16.1

Link to minimal reproduction

https://github.com/kukushouhou/umi-plugin-test

Steps to reproduce

通过脚手架直接生成工程后编译就能复现错误,以下是日志

F:\JavaScript\umi-plugin-test>npx create-umi@latest
┌   create-umi
│
○  Pick Umi App Template
│  Umi Plugin
│
○  Pick Npm Client
│  npm
│
○  Pick Npm Registry
│  taobao
│
○  What's the plugin name?
│  umi-plugin-test
│
└  You're all set!

npm WARN deprecated [email protected]: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
npm WARN deprecated @stylelint/[email protected]: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
npm WARN deprecated @floating-ui/[email protected]: Package renamed to @floating-ui/react

added 1044 packages in 21s

F:\JavaScript\umi-plugin-test>npm run build

> [email protected] build
> father build

info  - Clean output directories
info  - Bundless for src directory to cjs format
event - Bundless src/index.ts to dist\cjs\index.js (with declaration)
event - Generate declaration file...
error - TS5055: Cannot write file 'F:/JavaScript/umi-plugin-test/dist/cjs/index.js' because it would overwrite input file.
error - Error: Declaration generation failed.
    at getDeclarations (F:\JavaScript\umi-plugin-test\node_modules\father\dist\builder\bundless\dts\index.js:200:19)
    at transformFiles (F:\JavaScript\umi-plugin-test\node_modules\father\dist\builder\bundless\index.js:79:58)
    at async bundless (F:\JavaScript\umi-plugin-test\node_modules\father\dist\builder\bundless\index.js:107:19)
    at async builder (F:\JavaScript\umi-plugin-test\node_modules\father\dist\builder\index.js:55:25)
    at async Command.fn (F:\JavaScript\umi-plugin-test\node_modules\father\dist\commands\build.js:15:13)
    at async Service.run (F:\JavaScript\umi-plugin-test\node_modules\@umijs\core\dist\service\service.js:328:15)
    at async Service.run2 (F:\JavaScript\umi-plugin-test\node_modules\father\dist\service\service.js:58:16)
    at async Object.run (F:\JavaScript\umi-plugin-test\node_modules\father\dist\cli\cli.js:37:9)

What is expected?

预期是能正常输出.d.ts文件.

What is actually happening?

实际输出.d.ts文件时报"cjs/index.js"文件已存在的错误

Any additional comments? (optional)

我尝试Debug找问题没找到.
我尝试把断点打到getDeclarations方法上,然后编译中断时把"cjs/index.js"文件删除后继续执行,就能正常编译出"cjs/index.d.ts"文件.

info  - Clean output directories
logger.js:118info  - Bundless for src directory to cjs format
logger.js:122event - Bundless src/index.ts to dist\cjs\index.js (with declaration)
logger.js:122event - Generate declaration file...
logger.js:122event - Transformed successfully in 8686 ms (1 files)

感觉应该是判断文件是否存在的方法传参传错了,但我没找到这个方法具体在哪里

试过降级到v4.3.8和v4.3.7问题依然存在,也在MacOS下尝试过问题一致

@fz6m
Copy link
Contributor

fz6m commented Mar 16, 2024

这个问题在这一行日志:

error - TS5055: Cannot write file 'F:/JavaScript/umi-plugin-test/dist/cjs/index.js' because it would overwrite input file.

发现貌似是重复写了这个 js 产物文件,原因我没有细查,但添加 tsconfig 的 include 范围后可以正常构建了:

  "include": ["src"]

@PeachScript 有时间了可以辛苦看下这个是什么原因,现在 father 必须要添加 include 吗,entry 默认是 ./src/index 吧,其实就是默认 src 了;另外我理解 rootDir: "./src"outDir: "./dist" 这两个也是默认的行为,其实用户不在 tsconfig 里写这俩配置也无所谓。

@kukushouhou
Copy link
Author

输出的日志看似是再试图重复写这个index.js产物,但实际我debug时在getDeclarations方法中断执行,然后把index.js产物删除后继续执行,他最终只输出了index.d.ts文件,没有再次写入index.js文件,因此我不认为是他重复写了这个 js 产物文件.

具体debug过程如图:
PixPin_2024-03-17_01-42-40

@QDyanbing
Copy link

你好问题有修复吗,build的时候还是有遇到相似的问题

@QDyanbing
Copy link

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants