Coder Social home page Coder Social logo

Comments (6)

JakeChampion avatar JakeChampion commented on July 17, 2024

Howdy,
It looks to me like @hanazuki/node-jsonnet depends on running in a nodejs environment and expects nodejs built-in packages to exist such as fs and path. js-compute-runtime is not based on nodejs and does not have the same built-in packages as nodejs, which is why @hanazuki/node-jsonnet does not work

from js-compute-runtime.

rahul007-bit avatar rahul007-bit commented on July 17, 2024

Thank you for your reply and time!

the error also suggests that we can specify this "platform: 'node'" somewhere,
does this suggestion is provided by fastly-compute-runtime or honojs?

and once again Thank you so much for your time!! 🙏🏼

from js-compute-runtime.

JakeChampion avatar JakeChampion commented on July 17, 2024

Unfortunately setting "platform: 'node'" will not solve the issue as that is telling the bundler that your target environment is node and so has the node built-ins such as FS and path, but your target environment is not node and does not have those built-ins

from js-compute-runtime.

rahul007-bit avatar rahul007-bit commented on July 17, 2024

@JakeChampion That's unfortunate, but is there any way I can read files in js-compute-runtime from the src directory like JSON or yaml files so that I can find some alternative to @hanazuki/node-jsonnet

from js-compute-runtime.

JakeChampion avatar JakeChampion commented on July 17, 2024

Yes, you can include the file during build/compile time using includeBytes and then convert to a string and then parse using JSON/yaml.

Something like this:

/// <reference types="@fastly/js-compute" />

import { includeBytes } from "fastly:experimental";

const decoder = new TextDecoder();
const config = JSON.parse(decoder.decode(includeBytes('src/config.json')));

async function app() {
    return new Response("hello");
}
addEventListener("fetch", event => event.respondWith(app(event)));

An alternative would be to store the JSON/yaml files in a KV Store and then use the JSON method when reading them:

/// <reference types="@fastly/js-compute" />

import { KVStore } from "fastly:kv-store";

async function app(event) {
  const files = new KVStore('files')

  const entry = await files.get('config')
  const config = await entry.json()
  return new Response("hello")
}

addEventListener("fetch", (event) => event.respondWith(app(event)))

from js-compute-runtime.

rahul007-bit avatar rahul007-bit commented on July 17, 2024

This looks perfect!!
Once again, thank you for your time!

from js-compute-runtime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.