pxt-microbit icon indicating copy to clipboard operation
pxt-microbit copied to clipboard

Question: How can local dependencies be referenced in pxt.json

Open lobodpav opened this issue 5 months ago • 5 comments
trafficstars

Hello,

When developing my micro:bit v2 application using TypeScript, I forked an external dependency on GitHub to make a few changes that I want to propose as a Pull Request.

Now I need to link that local dependency to my application to test my changes.

In the pxt.json, dependencies are defined in this fashion:

{
    "dependencies": {
        "core": "*",
        "sonarbit": "github:elecfreaks/pxt-sonarbit#v1.0.9"
    }
}

I tried to change the above to:

{
    "dependencies": {
        "core": "*",
        "sonarbit": "local:../pxt-sonarbit"
    }
}

However, when running mkc build, I got

Exception: Error: Error: extension sonarbit is missing pxt.json

The pxt.json file is there. Even when changing the relative path to an absolute path, the same happened.

I know it's possible to achieve what I'm after in the online MakeCode editor. Is the same possible locally when using mkc? The online editor is so inconvenient for day-to-day development.

lobodpav avatar May 29 '25 17:05 lobodpav

@jwunderl ?

abchatra avatar May 29 '25 20:05 abchatra

You can commit and use the hash in the dependency, so: "sonarbit": "github:<your_fork>#<commit_hash>"

This can make a mess of version control in your fork unfortunately. I've never been able to get proper local development to work. Would love to hear that it's possible and I've been missing something.

ssande-fwd avatar Jun 03 '25 15:06 ssande-fwd

You can commit and use the hash in the dependency, so: "sonarbit": "github:<your_fork>#<commit_hash>"

This can make a mess of version control in your fork unfortunately. I've never been able to get proper local development to work. Would love to hear that it's possible and I've been missing something.

Yeah, that’s totally doable. But it's a workaround, forcing me to push every single change I need to test.

For day-to-day development, there are so many obstacles that I'm slowly giving up on micro:bit. It's meant to be very beginner-friendly, but it's not meant for serious coding IMO.

lobodpav avatar Jun 03 '25 16:06 lobodpav

When doing extension development where I temporarily have it in the local ./libs tree, I use dependency references like this:

{
    "dependencies": {
        "core": "file:../core",
        "sonarbit": "file:../pxt-sonarbit"
    }
}

ganicke avatar Jun 05 '25 21:06 ganicke

Yeah. That's why I thought it would work for regular projects too. For some reason, it does not.

lobodpav avatar Jun 06 '25 03:06 lobodpav