ventojs / vento

🌬 A template engine for Deno & Node
https://vento.js.org/
MIT License
169 stars 9 forks source link

Can't get it functioning on Node #16

Closed uncenter closed 10 months ago

uncenter commented 10 months ago

./index.js

import vento from "ventojs";

const vto = vento();
const template = vto.load("my-template.vto");

const result = template({ title: "Hello world" });
console.log(result.content);

./my-template.vto

{{ title }}

Output:

file:///.../index.js:6
const result = template({ title: "Hello world" });
               ^

TypeError: template is not a function
    at file:///.../index.js:6:16
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
    at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24)
    at async loadESM (node:internal/process/esm_loader:40:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.5.1

Using the example right from the README... what am I doing wrong? I also noticed there aren't any types? And are there plans for a CJS version?

oscarotero commented 10 months ago

Sorry, the examples in the README are wrong: Vento is async so you need the await keyword. This will work:

import vento from "ventojs";

const vto = vento();
const template = await vto.load("my-template.vto");

const result = await template({ title: "Hello world" });
console.log(result.content);

I also noticed there aren't any types?

Types are in mod.d.ts.

And are there plans for a CJS version?

I'm using dnt to generate the NPM package, I have to investigate if it's possible to define two targets (and configure properly the types).

uncenter commented 10 months ago

Closed by 0682490af773ff11cb7823ae30d374a07236d2da and fa5c5a2bd2b65a6ace18c44ce3d79acd8ac5565a.

uncenter commented 10 months ago

Can you publish the CJS version to NPM?

oscarotero commented 10 months ago

Done!

uncenter commented 10 months ago

@oscarotero is there any way to have a proper default export for the CJS version? dnt doesn't actually create a default export and forces you to access the default property like so:

const vento = require("ventojs").default;

Looks like there is an old issue on the dnt repo about this: https://github.com/denoland/dnt/issues/239