Skip to content

ESM distro for @inrupt/solid-client-authn-browser #3001

@riovir

Description

@riovir

UPDATE 2: Here's a small reproduction on Codesandbox make sure to interact with the preview on a separate browser tab to avoid a login-loop.
UPDATE: Changed workaround to use a more idiomatic way to force ESM transitive dependencies for Rollup / Vite.

Search terms you've used

  • esm
  • rollup
  • vite

Impacted environment

In which environment would the proposed feature apply?

  • The browser (with a bundler)
  • Node.js
  • Other (please specify): ...
  • I'm not sure.

Feature suggestion

The @inrupt/solid-client-authn-browser/package.json declares a valid ESM export. (With either an mjs extension or also the "type": "module" set).

Expected functionality/enhancement

It would be possible to use the package with modern bundlers, such as Vite.

Actual functionality/enhancement

When Vite does a production build the app seemingly works, but fails at runtime. The rabbit hole looks like this:

  • Vite uses Rollup for production builds (instead of ESBuild used during development)
  • Rollup concludes that @inrupt/solid-client-authn-browser is in CommonJS
  • Then, when processing the transitive dependencies, eventually imports the @inrupt/solid-client-authn-core however, picks the CommonJS edition. This edition, has been written with Node.js in mind, trying to use the node-fetch instead of the readily available fetch in the browser.

The ideal way to break that chain is to offer an ESM edition of the @inrupt/solid-client-authn-browser so that bundlers won't try to pick the CJS / Node version of transitives.

Use Cases

Trying to build a basic Vue.js app with Vite instead of Webpack. The Vue community has been slowly backing away from Webpack, instead putting their effort into Vite (ESBuild for dev, Rollup for prod builds). Unfortunately, without hacking into node_modules with patch-package I was unable to create a working production build.

Additional information

As a workaround I explicitly list most of the transitive dependencies of @inrupt/solid-client-authn-browser and use a customResolver that's forced to pick ESM versions

As a workaround / hack I patched up the @inrupt/solid-client-authn-core package locally, to expose its ESM build even when require is in use. Mostly to avoid using the node-fetch that fails in the browser. However ideally, I hoped that the bundler can pick a browser / ESM targeted format of the packages.

Note that a fix for this would likely close #1815 as well. Also note that 2 more adjustments seemed to be necessary so that the project builds: https://gitlab.com/riovir/babalog/-/blob/main/vite.config.ts#L20-21

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions