-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Export everything from a single index.ts. #3
Comments
This came up because I was trying to use chessops as a dependency and import one of the modules from it. For example:
|
That's suprising. Based on microsoft/TypeScript#8305 and https://www.typescriptlang.org/docs/handbook/module-resolution.html#node ff I expect this to work. Example usage in lila, the main consumer of this library:
Maybe a subtle issue with lila uses this to include only relevant modules instead of the whole bundle. In any case I am not opposed to adding |
Thanks for the quick response. Does lila install chessops as a dependency via npm or does it have a local checkout? Edit: Ah I see already, installed as a dependency. Let me try and use lila's tsconfig to see if that changes anything. |
Indeed, adopting the |
@niklasf Bundlers are, usually, able to handle package-relative imports and the output bundle is a single-file, so that is how most users "work around" (really, never notice) the problem. The problem crops up if you are trying to use native ES modules natively either in the browser or (I believe) in NodeJS 13+. In such situations, resolution fails because |
It is worth noting that I suspect the problem @ajrouvoet had may be unrelated, when they popped into the TypeScript discord seeking advice I noticed the package-relative import for their web project which is what lead me to file this issue. You are correct that TypeScript should be able to compile with package-relative imports, even if they won't work at runtime in a browser. |
Does 3d7e044 look reasonable? (Mostly flat re-exports, except for some non-essential modules.) I'll keep the example/docs as is, because I believe the module-relative imports are still the best way to use this library in TypeScript or with bundlers. |
Looks good to me, but I'm just starting out with typescript :) |
Published as v0.4.0. |
Yeah, all looks reasonable to me, thanks! |
import ... from '.../something'
is not valid in ES6 modules as it mixes package import syntax and relative file import syntax. All exports should be consolidated in a single file that re-exports things from other files. You can either do namespaced re-exports or singular re-exports, depending on what makes the most sense for the project.The text was updated successfully, but these errors were encountered: