Issue #168 - Workaround for import errors when using typescript #382
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
I investigated a little the Issue #168 because I am having the same problem and it is heavily slowing down my development.
It seems like the problem is mainly related to rollup.js and the decisions it makes while bundling the files.
My changes should be seen as a workaround more than a long term fix.
What I did change.
While by adding a second export, even if it is unused, it will correctly translate as:
which is what i think you expected to happen when the code was originally written (just like it happens in the date-holidays-parser library.
Thus, I added a "DumbClass" that does absolutely nothing but since it's imported it will force rollup.js to behave as expected.
Then it expects to be imported as
instead of
I could not figure out an elegant way of force rollup to do the import right, so i wrote a fast bash script that will do the postbuild and fix the import.
How did I test the changes.
I checked that the
yarn test
is still ok, so hopefully I did not introduced any breaking change for the JS users.Then, I created a second project in typescript with the same configuration as the Issue #168 bug reporter, imported the library locally with npm and tested my changes.
Conclusion
Please, reach out to me if this PR is not complete. I did not had time to fully read the documentation but for what i understood I should have done every required step.
I know this is more of a workaround, but I need this to be fixed FAST as I am currently working with this library.
In the future, i would suggest to deprectate these default exports and create a new major version with module exports only, that are easier to manage with this whole bundle-up / typing stuff.
I would be happy to help with that!