Skip to content

JSR package CommonJs dependency is not transpiled by Vite #1097

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

Open
danielbeeke opened this issue May 4, 2025 · 0 comments
Open

JSR package CommonJs dependency is not transpiled by Vite #1097

danielbeeke opened this issue May 4, 2025 · 0 comments

Comments

@danielbeeke
Copy link

danielbeeke commented May 4, 2025

Use case

I try to use JSR in the context of front end libraries and a browser app. I published @shapething/shacl-renderer. When trying to import it in Vite the commonjs dependencies are not transpiled / picked up.

Minimal working example

https://github.com/danielbeeke/mwe-jsr-react-commonjs

Error

Uncaught Error: Module "npm:jsonld-context-parser@^3.0.0" has been externalized for browser compatibility. Cannot access "npm:jsonld-context-parser@^3.0.0.JsonLdContextNormalized" in client code.  See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
    get __vite-browser-external:npm:jsonld-context-parser@^3.0.0:3
    <anonymous> main.tsx:1
__vite-browser-external:npm:jsonld-context-parser@^3.0.0:3:12

The problem seems to be that the package is not resolved when running the project. It is transpiled into this:

/** @jsxRuntime classic *//** @jsxFactory React.createElement *//** @jsxFragmentFactory React.Fragment */import { JsonLdContextNormalized } from "npm:jsonld-context-parser@^3.0.0";
import { JSX } from "npm:react@^19.0.0";

type Props = {
  prefixes?: Record<string, string>;
  iri: string;
};

export default function Compactor ({ iri, prefixes }: Props): JSX.Element {
  const context = new JsonLdContextNormalized({
    ...prefixes,
  });

  return <span>{context.compactIri(iri)}</span>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs Triage
Development

No branches or pull requests

1 participant