fix: avoid packageJson without name in resolveLibCssFilename#19324
Conversation
|
Why does the
Maybe we should improve the error instead saying that the package.json is malformed? |
|
I think those requirements are only enforced for published packages. |
There was a problem hiding this comment.
I think this part needs to be fixed as well.
vite/packages/vite/src/node/build.ts
Lines 922 to 932 in e8c783f
There was a problem hiding this comment.
@sapphi-red Just confirm: I saw several test cases particular on packages/noname. Do you think it should be updated to packages/name as well? Thanks.
https://github.com/vitejs/vite/blob/main/packages/vite/src/node/__tests__/build.spec.ts
There was a problem hiding this comment.
I think it should be packages/noname as-is, but the resolved name should be updated so that we test the fallback behavior.
There was a problem hiding this comment.
Test case updated. I also added an additional packages/vite/src/node/__tests__/packages/package.json to catch the resolver for noname. Please take a look. 🙏
| const packageJson = findNearestPackageData(root, packageCache)?.data | ||
| const name = packageJson ? getPkgName(packageJson.name) : undefined | ||
| const name = | ||
| packageJson && packageJson.name ? getPkgName(packageJson.name) : undefined |
There was a problem hiding this comment.
We have findNearestMainPackageData function that skips the package.json without name field. I think swapping findNearestPackageData with it matches the users expectations.
vite/packages/vite/src/node/packages.ts
Lines 161 to 162 in e8c783f
|
Sometimes there're nested |
resolveLibCssFilename
|
Just FYI: I've found the root cause of this error is that I didn't set |
Description
Fix the issue when there is no package name in package.json.
which causes errors like below: