Skip to content

Conversation

@kanadgupta
Copy link
Contributor

@kanadgupta kanadgupta commented Nov 12, 2025

🧰 Changes

was seeing this error when attempting to load a vite server module in our main repo:

file:///Users/kanadg/Code/readmeio/readme/packages/react/dist/hub/server/node.mjs:46
import { uppercase } from "@readme/syntax-highlighter";
         ^^^^^^^^^
SyntaxError: Named export 'uppercase' not found. The requested module '@readme/syntax-highlighter' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '@readme/syntax-highlighter';
const { uppercase } = pkg;
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:226:21)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async ModuleJob.run (node:internal/modules/esm/module_job:335:5)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26)
    at async makeHubProps (/Users/kanadg/Code/readmeio/readme/packages/react-interop/middleware/hub/index.ts:184:16)
    at async /Users/kanadg/Code/readmeio/readme/packages/react-interop/middleware/hub/index.ts:295:27
    at async /Users/kanadg/Code/readmeio/readme/packages/hub/controllers/git/doc.ts:199:17

this is happening because vite is a bit stricter about how it resolves modules compared to webpack. this library has a mix of default/non-default exports and ill-defined exports that are throwing off vite's module resolver.

in order to address this, i've added a new utils export (i.e., import { uppercase } from '@readme/syntax-highlighter/utils') that exposes fully-typed versions of these util functions. all of these util functions are vanilla JS and zero deps so if we switch to those imports, i bet we'll see better treeshaking.

in addition to the above, i went through and did some routine cleanup in this repo since i've barely touched it prior to now:

  • introduces basic typescript config and converts a few files1 to TS. the utils that we're now exposing are fully typed for usage downstream 💖
  • adds ts-loader so webpack can properly handle typescript (my god i hate webpack)
  • moves to vitest for test runner (since, unsurprisingly, jest completely crapped out once i started this refactor)
  • updates the minimum node.js version to node 222
  • introduces knip into the mix and cleared out a bunch of deps as a result

🧬 QA & Testing

again, there should be no functional changes, just introducing a bit more API surface area so bundlers like vite can play nicely with this library.

not sure how to test this other than ensuring that tests pass? would love some pointers on how to QA this! to be safe, i'd recommend we release this as a beta and test it out in our main repo before publishing it to the main latest channel.

Footnotes

  1. there are a handful of files that i didn't get around to converting to TS and i think it's fine for now.

  2. even though i think the main changes should be backwards compatible, i bet it'll break certain bundler setups so i think we should do a major version bump. hence i bumped the minimum node.js requirements here. in bumping our minimum node version, i was also able to remove the glob dependency and use native fs.globSync 😌

- introduces typescript config
- converts a bunch of files to typescript
- creates a new export object that exposes utils directly
- adds `ts-loader` so webpack can handle typescript
- moves to vitest for test runner
this gets the legacy bundles working (i think)
This reverts commit 3226d1a.
- use native node.js glob
- remove prettier@2
- add in @csstools/css-parser-algorithms so tests can work in CI?
@kanadgupta kanadgupta changed the title feat: vite-friendly overhaul feat: new vite-friendly /utils exports Nov 12, 2025
@kanadgupta kanadgupta added enhancement New feature or request dependencies Pull requests that update a dependency file refactor Issues about tackling technical debt labels Nov 12, 2025
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a barrel file that exposes the util functions so they can be accessed via the new @readme/syntax-highlighter/utils export

optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
minimize: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i don't think we should be optimizing in this repo for a few reasons:

  • in my local testing, our legacy webpack build in our main repo can't handle these changes (which are so small so i can't really fathom why)
  • harder to troubleshoot (i generally am opposed to minification for npm libraries for this reason)
  • this package is being fed into bundlers in our downstream repos and i'd rather let those take care of the minification

{
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

CleanShot 2025-11-12 at 10 45 04

Copy link
Member

Choose a reason for hiding this comment

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

ts-loader? i dont ts-knower

@kanadgupta kanadgupta marked this pull request as ready for review November 12, 2025 19:18
@kanadgupta kanadgupta requested a review from erunion as a code owner November 12, 2025 19:18
{
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
Copy link
Member

Choose a reason for hiding this comment

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

ts-loader? i dont ts-knower

import canonical from './utils/canonical';
import { modes } from './utils/modes';
import uppercase from './utils/uppercase';
import canonical from './utils/canonical.ts';
Copy link

Choose a reason for hiding this comment

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

maybe you answered this somewhere, but why did you have to add the .ts to these imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good q! i added these because eslint was yelling at me 🤷🏽 pretty sure webpack can handle these whether or not they have file extensions

@bnikom
Copy link

bnikom commented Nov 12, 2025

i belieb u
6F18C72B-D98F-4DE9-A3DD-B1048864DCCB

@kanadgupta kanadgupta merged commit 2693b56 into main Nov 12, 2025
5 checks passed
@kanadgupta kanadgupta deleted the kanad-2025-11-11/overhaul branch November 12, 2025 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement New feature or request refactor Issues about tackling technical debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants