plausible / plausible-tracker

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

Source maps in the npm package reference nonexistent files #22

Closed tchebb closed 2 years ago

tchebb commented 2 years ago

Versions

Describe the bug

The source map comments included in the npm package point to source files that don't exist in the package. For example, build/module/index.js has the following contents:

import Plausible from './lib/tracker';
export default Plausible;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxTQUFTLE1BQU0sZUFBZSxDQUFDO0FBSXRDLGVBQWUsU0FBUyxDQUFDIn0=

sourceMappingURL decodes to this JSON:

{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,eAAe,CAAC;AAItC,eAAe,SAAS,CAAC"}

which indicates that the original TypeScript source can be found at ../../src/index.ts. But the src/ directory doesn't exist at all in the package! This causes a warning from source-map-loader when run from a downstream packages and makes this code harder to debug.

Expected behavior

The source maps should be well-formed: either they should refer to files that exist or they should embed the TypeScript source directly using a "sourcesContent" key.

Steps to reproduce

  1. Add plausible-tracker 0.3.4 as a dependency to a project that runs source-map-loader as part of its build.
  2. Build that project.
  3. Observe three warnings like the following are printed.
WARNING in ./node_modules/plausible-tracker/build/module/index.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '.../node_modules/plausible-tracker/src/index.ts' file: Error: ENOENT: no such file or directory, open '.../node_modules/plausible-tracker/src/index.ts'
 @ ./src/analytics/plausible.ts 3:0-42 11:29-38
 @ ./src/index.tsx 8:0-55 13:0-14
tchebb commented 2 years ago

The issue is resolved for me with v0.3.5. Thanks!