Skip to content

Supporting both npm and JSR with peerDependencies and import resolution is confusing and brittle #1105

Closed
@thedanchez

Description

@thedanchez

Publishing a library to both npm and JSR is currently a painful experience due to the mismatch between how each handles peerDependencies and module resolution. I'm not an expert on JSR as I only recently started publishing packages to it.

What I'm trying to do

I have a library that has the following peerDependencies (from my package.json):

"peerDependencies": {
  "@dschz/load-script": ">=1.0.4",
  "solid-js": ">=1.8.0"
}

The thing to note particularly here is that @dschz/load-script is another library of mine and it exists in both NPM and JSR. With the above set, I have the following import line in one of my source files:

import { loadScript } from "@dschz/load-script";

Publishing to npm works fine, but when I attempt to publish to JSR, I get the following error:

Publishing @dschz/solid-create-script@1.2.1 ...
error: Failed to publish @dschz/solid-create-script@1.2.1

Caused by:
    Failed to publish @dschz/solid-create-script at 1.2.1: failed to build module graph: Module not found "file:///src/@dschz/load-script".
        at file:///src/createScript.tsx:1:157
Child process exited with: 1

I tried adding an import_map.json file with the following content thinking that it would resolve my publish problem, but it did not:

{
  "imports": {
    "@dschz/load-script": "jsr:@dschz/load-script@1"
  }
}

I am at a loss at what to do here as I would like to publish my packages across both NPM and JSR but this issue is making it very hard for me to take JSR seriously.

Lastly, my jsr.json is the following:

{
  "name": "@dschz/solid-create-script",
  "version": "1.2.1",
  "license": "MIT",
  "exports": "./src/index.tsx",
  "publish": {
    "include": ["LICENSE", "README.md", "import_map.json", "src/**/*.tsx"],
    "exclude": ["**/*.test.tsx"]
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions