Repository navigation
Scope the CJS and UMD builds to CommonJS so Node and Vite SSR can import the package - #41
Open
eastagiletracker wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR proposes making the CommonJS and UMD builds loadable from Node again, so
import { SpinnerCircularFixed } from 'spinners-react'works under Vite/Astro SSR (Fixes #34). We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/1168. You can sign in with your GitHub ID to claim ownership of the project.What was wrong
Since 1.0.11
package.jsondeclares"type": "module", butmainstill points atlib/umd/index.jsand the README documentsrequire('spinners-react/lib/cjs/...'). Node decides how to parse a.jsfile from the nearestpackage.json, so it now parses the UMD and CJS bundles as ES modules: the UMD wrapper finds noexportsobject and exports nothing, and the CJS chunks throwrequire is not defined in ES module scope. Bundlers are unaffected because they followmoduletolib/esm, which is why this only shows up when Node loads the package itself, as Vite does for externalized dependencies during SSR. That is exactly the setup in #34, and why thessr.noExternalworkaround in the thread helps.The fix
rollup.config.jsnow emits a one-linepackage.jsoncontaining{ "type": "commonjs" }intolib/cjsandlib/umd. Node scopes the files in those folders back to CommonJS, while the root stays"type": "module"andlib/esmkeeps loading as ESM. No file is renamed and no entry point moves, so the unpkg UMD URLs, themodule/typesfields and every documented deep import path stay exactly as they are.Reproduction at current
masterand verificationI built
master, rannpm pack, and installed the tarball withreact@19into an empty project. Thennode check.mjswithimport { SpinnerCircularFixed } from 'spinners-react'fails with the same error as the issue:A CommonJS consumer gets
require('spinners-react').SpinnerCircularFixed === undefined, andrequire('spinners-react/lib/cjs/SpinnerCircular')throwsReferenceError: require is not defined in ES module scope. With the same project on Vite 6,ssrLoadModuleon a file that imports the spinner gives[vite] The requested module 'spinners-react' does not provide an export named 'SpinnerCircularFixed'.I then repacked with this change and reinstalled. The same scripts (which also cover a deep
lib/esm/SpinnerCircular.jsimport,lib/cjsandlib/umddeep requires, and arenderToStringof the component) now print:npm run lint,npm run types,npx jest(10 suites, 55 tests, 19 snapshots) andnpm run buildall pass both before and after the change, with no new failures. The Jest suite runs againstsrcand can't see the packed output, so the tarball check above is what covers this change. To replay it, runnpm run build && npm pack, install the.tgznext toreactin an empty folder, and runnode -e "import('spinners-react').then(m => console.log(typeof m.SpinnerCircularFixed))".How this was managed
This work is tracked as https://eastagiletracker.com/projects/1168/stories/1364986 on https://eastagiletracker.com/projects/1168, a board imported from this repo's issues and pull requests (40 stories) and used to manage this change.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com