eta-dev / eta

Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript
https://eta.js.org
MIT License
1.41k stars 65 forks source link

3.1.0 does not work in deno out of the box #253

Closed morandd closed 1 year ago

morandd commented 1 year ago

Describe the bug Does not work on a simple example using latest deno and v3.1.0

To Reproduce

  1. Create a simple template file like this: mkdir templates; echo "hello world" > templates/test.eta

  2. Create a simple Eta test script like this "test.js":

    
    import { Eta } from "https://deno.land/x/eta@v3.1.0/src/core.ts";

const eta = new Eta({ views: Deno.cwd() + '/templates' })

const res = eta.render("./test.eta", { name: "Ben" }) console.log(res) // Hi Ben!


3. Run the test script:
`deno run --allow-read test.js`

See the error:

error: Uncaught Eta Error: Failed to get template './test.eta' throw new EtaError("Failed to get template '" + template + "'"); ^ at Eta.handleCache (https://deno.land/x/eta@v3.1.0/src/render.ts:34:13) at Eta.render (https://deno.land/x/eta@v3.1.0/src/render.ts:53:30) at file:///[LOCAL PATH HIDDEN FOR PRIVACY]/test.js:6:17


I tried many permutations for `view` and lots of variation on leading and trailing ./ and /.  
nebrelbug commented 1 year ago

@morandd, everything is correct with your code except one small detail -- you need to import Eta from index.ts, not core.ts. The full correct import should be:

import { Eta } from "https://deno.land/x/eta@v3.1.0/src/index.ts";

Sorry for the confusion!