Using jsonnet in node/js with imports

669 views
Skip to first unread message

Gavin McFarland

unread,
Aug 1, 2019, 5:43:38 PM8/1/19
to Jsonnet
Hi,

I'm currently using jsonnet in a project using this version of node-jsonnet.

Unfortunately, imports don't appear to work and the packages are unsupported now. When you try to import another jsonnet file or libsonnet you receive the following error:

RUNTIME ERROR: Couldn't open import "test.libsonnet": No match locally or in the Jsonnet library paths.
        snippet:1:18-40 thunk <martinis>
        snippet:48:19-26        object <anonymous>
        During manifestation

I suspected maybe this was due to how jsonnet has been ported and using a wrapper that this functionality was not available. I'm not entirely sure because I come from a HTML/CSS background and I'm not familiar with how jsonnet works.

This version of node-jsonnet also suffers the same issue above.

I then tried to compile a js version of jsonnet using emscripten but I couldn't get it to work as there was issues with installing  emscripten, so then I thought I'd have a go at compiling go-jsonnet using gopher but then I didn't realised I'd have learn Go to get it to work, and I hit too many road blocks.

I'm able to use the jsonnet command line and that supports imports but because my tool is something I'd like others to be able to use it's not as convincing to require them to setup the CLI version to  compile their files.

Is there another way I could use jsonnet in my node application that supports imports?

Many thanks,
Gavin

Paul Rudin

unread,
Aug 2, 2019, 2:41:11 AM8/2/19
to Jsonnet

Dave Cunningham

unread,
Aug 2, 2019, 8:00:19 AM8/2/19
to Paul Rudin, Jsonnet
It was intended to be used on websites like jsonnet.org, where it doesn't make sense to allow file access.  So what there is is a callback you can use to resolve imports.  It's only ever been used to import from a set of hardcoded files for demo purposes but I don't see why you can't use it to read actual files: https://github.com/google/jsonnet/blob/master/doc/js/demo.js#L35

--
You received this message because you are subscribed to the Google Groups "Jsonnet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/0caadc92-e366-4118-9c4a-cc8fe019dcf6%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages