Skip to content

Conversation

@ErkoRisthein
Copy link

@ErkoRisthein ErkoRisthein commented Dec 11, 2025

Summary

Fixes "Failed to parse source map" warnings when using the library with bundlers like webpack that use source-map-loader.

The root cause was that the module field pointed to web-eid.js at package root, where source map paths (../../src/) were invalid after being copied from dist/node/ by the prepack script.

Changes

  • Set main, module, and types to dist/node/web-eid.js
  • Add exports field for clean subpath imports (e.g., @web-eid/web-eid-library/models/ActionOptions)
  • Include src/**/* for source map resolution and dist/node/**/* for the entry points
  • Update README import examples to use simpler paths
  • Keep prepack/postpack for backwards compatibility with direct file imports

Backwards Compatibility

Direct file imports like @web-eid/web-eid-library/web-eid still work because prepack copies files to root.

Test Plan

  • npm run build succeeds
  • npm pack creates valid package
  • Install in a webpack project and verify no source map warnings
  • Verify imports work: import { authenticate } from '@web-eid/web-eid-library'
  • Verify subpath imports work: import ActionOptions from '@web-eid/web-eid-library/models/ActionOptions'

Signed-off-by: Erko Risthein erko@risthein.ee

Changed module entry point from root to dist/node/ where source maps
have correct relative paths. Previously, the prepack script copied
files to root, breaking source map paths that expected to be two
directories deep (../../src/).

Changes:
- Set main/module/types to dist/node/web-eid.js
- Add exports field for clean subpath imports
- Include src/**/* and dist/node/**/* in package files
- Update README import examples
- Remove npm link "Cons" section (exports field fixes this)

The prepack/postpack scripts are kept for backwards compatibility
with direct file imports like '@web-eid/web-eid-library/web-eid'.
Copilot AI review requested due to automatic review settings December 11, 2025 10:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes source map resolution warnings when using the library with modern bundlers like webpack. The fix restructures the package.json module entry points to use the dist/node/ directory, adds comprehensive subpath exports, and includes source files in the published package for proper source map resolution.

  • Updated main, module, and types fields to point to dist/node/web-eid.js instead of root-level files
  • Added exports field with wildcard patterns for clean subpath imports of models, errors, services, and utilities
  • Included src/**/* in the files array to enable source map resolution by bundlers

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
package.json Restructured module entry points to use dist/node/, added exports field for subpath imports, and included source files for source map support
README.md Updated import examples to use the new simplified import paths (direct package import instead of /web-eid subpath) and removed outdated npm link documentation about longer import paths

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…claration

- Add "type": "module" to clarify ES module intent
- Change "main" to point to UMD build for CommonJS consumers
- Add "require" condition to exports for CommonJS support
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Rename UMD bundle outputs from .js to .cjs extension
- Update main and exports to reference .cjs files
- Add exports for dist bundles (es, umd, iife) for direct imports

This ensures Node.js correctly parses UMD as CommonJS while
the package is declared as ESM.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant