Global object (window) confusion
See original GitHub issueDescribe the bug
Readme states that MatomoTracker
instance may be initialized like so
import MatomoTracker from '@datapunt/matomo-tracker-js'
const MatomoInstance = new window.MatomoTracker({})
and later uses syntax without window:
import MatomoTracker from '@datapunt/matomo-tracker-js'
const MatomoInstance = new MatomoTracker({})
however latter doesn’t work (at least in rollup builds) as it holds es-module wrapper {__esModule: true, default: ƒ}
.
~Same object is also leaking via window.MatomoTracker_1
.~
IMHO it’s not necessary to set class on window object, as it’s already exported via IIFE in rollup config.
To Reproduce As in description
Expected behavior
When importing MatomoTracker it’s possible to initialize it via new MatomoTracker({})
.
The window.MatomoTracker
property is available when using ES5 prebuilt bundle.min.js
.
Screenshots N/A
Desktop (please complete the following information): N/A
Smartphone (please complete the following information): N/A
Additional context Proposed solution:
- remove code block responsible for setting global object
- to preserve semver backward compatibility release in v1.x
- fix readme so examples are consistent
When running yarn run build
, rollup shows warnings related to this issue:
src/index.ts → bundle.min.js...
(!) Mixing named and default exports
https://rollupjs.org/guide/en/#output-exports
The following entry modules are using named and default exports together:
src\index.ts
Consumers of your bundle will have to use chunk['default'] to access their default export, which may not be what you want. Use `output.exports: 'named'` to disable this warning
This is caused by exporting both default and named exports together in index.ts:
export default MatomoTracker
export { types }
I wonder do we need to export types (here)?
I’d recommend removing types from index.ts and defining in package.json
{
"main": "lib/index.js",
"types": "lib/types.ts"
}
Related commit: https://github.com/Amsterdam/matomo-tracker/commit/c6c2324627a4a75dee35d3538233ac93a5e2bf67
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Correct, and in the next version we will get rid of
window.MatomoTracker
entirely.Probably fixed by #196 and #197