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

Regression: preconstruct build failes when json files are part of the package #582

Closed
mycroes opened this issue Nov 24, 2023 · 0 comments · Fixed by #592
Closed

Regression: preconstruct build failes when json files are part of the package #582

mycroes opened this issue Nov 24, 2023 · 0 comments · Fixed by #592

Comments

@mycroes
Copy link
Contributor

mycroes commented Nov 24, 2023

When upgrading from preconstruct 2.2.2 to 2.8.1 our builds fail when json files are part of the project. The output from preconstruct is as follows:

> yarn preconstruct build
🎁 error Generating TypeScript declarations for packages/datalog/src/translations/datalogTranslations.en.json failed:
🎁 error
🎁 info If you want to learn more about the above error, check https://preconstruct.tools/errors
🎁 info If the error is not there and you want to learn more about it, open an issue at https://github.com/preconstruct/preconstruct/issues/new

The failure is due to the following line in the rollup plugin:

if (!emitted.types || diagnostics.length) {

I think this is the result of the decision in TypeScript not to emit .d.ts for json files.

In preconstruct 2.2.2 the build would pass and the json data would be available from the main entrypoint (which is where the data was exported in my specific usecase). However, looking at the .d.ts files produced by preconstruct 2.2.2 I see it's importing the type definition for the json files by importing the json file directly (which is exactly how TypeScript handles this anyway). The json files however are not part of the package, so the type definitions for the json files are missing either way.

Regardless of the fact it wasn't perfect in preconstruct 2.2.2, the current state prevents us from building packages with newer preconstruct at all. I'm also fully aware I can replace the json files with ts files, but this is related to tooling (as you can see from the error it's about translation files). My guess is json files would need a bit of specific handling, just as TypeScript is explicitly handling json files (so yes, the situation is not great either way).

I did notice that if TypeScript declarationDir is different from outDir that the paths for josn files referenced in index.d.ts (or whatever the importing file would be) are actually pointing to the path relative to outDir, because the json files are not copied to declarationDir as well. I'm not even sure if this is properly consumed by TypeScript, but that's of course not a preconstruct issue. It probably will 'hurt' preconstruct though because the declarationDir is always separate.

Please let me know if you're open to adding support for handling json files. In that case I might be able to implement the support myself, but if you don't want to include explicit json file handling I won't attempt it.

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