-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESM distro for @inrupt/solid-client-authn-browser #3001
Comments
Thanks for reporting - we will look into this.
I'm surprised this is happening; note that @inrupt/solid-client-authn-core and @inrupt/solid-client-authn-browser both use @inrupt/universal-fetch under the hood which should only resolve to node-fetch when targeting node environments (with versions of node lower than 16.8 - see https://github.com/inrupt/universal-fetch/blob/main/src/index.ts). What error were you getting that indicated this was happening and/or do you have a minimal repro?
The What error were you getting that required the |
Without the patch hack, ESBuild (development mode of Vite) works correctly. (Cool, let's deploy!) Then to my surprise, the prod build was unable to log me into my pod provider. Instead, the page just seemingly reloaded and nothing happened. So I grabbed a console.log and dove head-first into node_modules. Turned out that the CJS edition of the transitive dependencies was bundled in, and the universal-fetch trying to use node-fetch silently failed (a catch block swallowed the error). Therefore I was never able to reconstruct the Session. That prompted me to find a way to force ESM editions to the transitive packages required by
The
With the original workaround, I got the following warning without it:
This is merely a symptom of the bundler picking the CJS edition of the package intended for the server. The new workaround indeed makes it unnecessary. |
Update: by explicitly listing the dependencies of That said, this needs quite some dive into the Vite / Rollup config, plus an understanding of why the bundler gets confused by the CJS format of the browser library. An ESM build would be a big step toward a happy out-of-the-box experience. |
I've created a small reproduction on Codesandbox: https://codesandbox.io/p/sandbox/vite-forked-vs5l4c |
I also noticed that it's not CJS per se that causes the issue in the The only security-supported Node version that doesn't have native fetch() support is Node 16 LTS, until 11 Sep 2023. |
We encountered a problem using |
SWhat universal fetch does is:
An error report would be useful @elf-pavlik as I am not expecting such a change in behavior between Node 16 and Node 18. |
reported in #3004 and fails in the |
Appreciate the update! I could remove a big chunk of Vitest code to make sure the |
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
Impacted environment
In which environment would the proposed feature apply?
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:
@inrupt/solid-client-authn-core
however, picks the CommonJS edition. This edition, has been written with Node.js in mind, trying to use thenode-fetch
instead of the readily availablefetch
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 acustomResolver
that's forced to pick ESM versionsAs 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
The text was updated successfully, but these errors were encountered: