Skip to content

Publish is replacing "file://" with "../../../../../" and dynamic imports from local files isn't working without "file://" prefix. #670

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

Closed
KyleJune opened this issue Jul 28, 2024 · 0 comments
Labels
publishing Problems with publishing

Comments

@KyleJune
Copy link

KyleJune commented Jul 28, 2024

When I was publishing one of my modules, I was running into issues with one of my scripts. I found an issue with file path imports.

Originally I had the following:
https://jsr.io/@udibo/react-app/0.20.1/build.ts#L201

        const mainMod =
          (await import(path.join(routesUrl, mainPath))) as RouteFile;

The intent was to read a file from their machine as part of a script that builds an application. What I found was after switching from deno.land/x to jsr.io, how that resolves is different. It would end up resolving as if the path was relative to the jsr.io link to the package instead of the file on the machine running the script.

I tried fixing that by adding a "file://" prefix. When I published that change, I found it was transforming my code.
https://jsr.io/@udibo/react-app/0.20.2/build.ts#L201

        const mainMod = (await import(
          "../../../../../" + path.join(routesUrl, mainPath)

The original code before publishing was the following:

        const mainMod = (await import(
          "file://" + path.join(routesUrl, mainPath)

So it seems that the publish command is just replacing it.

I did find a workaround to allow me to read from the local file. The following works and allows me to read the local file.
https://jsr.io/@udibo/react-app/0.21.0/build.ts#L202

        const mainMod = (await import(
          path.toFileUrl(path.join(routesUrl, mainPath)).toString()
        )) as RouteFile;

If the behavior of preventing imports of local files is intentional and this workaround is a bug, is there a proper way of enabling a script on jsr.io from dynamically importing from a file on the users machine? The intent is to access a file that defines a route to determine how to include it in the build that my script is generating.

Edit: I ended up changing my script to no longer need to dynamically import the file.

@github-project-automation github-project-automation bot moved this to Needs Triage in JSR Jul 28, 2024
@crowlKats crowlKats added the publishing Problems with publishing label Jan 16, 2025
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in JSR Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
publishing Problems with publishing
Projects
Status: Done
Development

No branches or pull requests

3 participants