Hookyns / tst-reflect

Advanced TypeScript runtime reflection system
MIT License
328 stars 11 forks source link

[Question] npm package using tst-reflect cannot be imported #82

Closed uplight-dev closed 1 year ago

uplight-dev commented 1 year ago

Created an npm package with an index.ts which exports several ts files to be referenced by the project importing this package. tst-reflect seems to generate this import statement even for the index.js file generated in dist of the npm package.

import * as _ßr from "tst-reflect";

Getting this error in the project importing this package: SyntaxError: Cannot use import statement outside a module

Any idea why?

Thanks!

Hookyns commented 1 year ago

Hello @uplight-dev,

there is an issue that adds import * as _ßr from "tst-reflect"; into every TS file included in a project, so if you have .ts files in the package, the project using that package has to include those .ts files and transpille them too, so it will add that line into them too.

You should publish only .js and .d.ts files. If your package contains some function with generic type parameter and you want end-project to use that function, it does not have to be published as .ts file but you can "decorate" it by JSDoc /** @reflect */.

But I'll try to fix the main issue here so the import * as _ßr from "tst-reflect"; is not added to every file.