plausible / plausible-tracker

Frontend library to interact with Plausible Analytics
https://github.com/plausible/plausible-tracker
MIT License
214 stars 46 forks source link

Update type exports to avoid TS1128 error on build #33

Closed caspervg closed 2 years ago

caspervg commented 2 years ago

Description

Current version on NPM breaks when building with an Angular project. It returns the following error on build:

ERROR in node_modules/plausible-tracker/build/main/index.d.ts(3,1): error TS1128: Declaration or statement expected.
node_modules/plausible-tracker/build/main/index.d.ts(3,13): error TS1005: ';' expected.
node_modules/plausible-tracker/build/main/index.d.ts(3,39): error TS1005: ';' expected.
node_modules/plausible-tracker/build/main/index.d.ts(4,1): error TS1128: Declaration or statement expected.
node_modules/plausible-tracker/build/main/index.d.ts(4,13): error TS1005: ';' expected.
node_modules/plausible-tracker/build/main/index.d.ts(4,35): error TS1005: ';' expected.

The original code does not seem to be supported

export type { PlausibleOptions } from './lib/tracker';
export type { EventOptions } from './lib/request';

Instead it has been replaced by the following, which fixes that issue.

import PlausibleOptions from './lib/options';
import EventOptions from './lib/request';
export type PlausibleOptions = PlausibleOptions;
export type EventOptions = EventOptions;

Related Issue

Screenshots or GIFs (if appropriate):

image

Types of changes

Checklist:

ukutaht commented 2 years ago

Thanks for reporting!

I don't see how your fix could work, because the './lib/options' file doesn't exist. This also causes the CI tests to fail. Does this change fix the issue for you locally?

caspervg commented 2 years ago

Thanks for reporting!

I don't see how your fix could work, because the './lib/options' file doesn't exist. This also causes the CI tests to fail. Does this change fix the issue for you locally?

Yep, it actually does fix the issue for me locally. But it turns out it is heavily dependent on the TypeScript version that is running locally. So this is actually not a good solution. Nevertheless it would still be nice to find a solution that works with any TypeScript version, of course :)

ukutaht commented 2 years ago

Absolutely. I will close this PR for now since it's not a complete solution.