marko-js / vite

A Marko plugin for Vite
MIT License
55 stars 8 forks source link

Nested dynamic routes cause template ENOENT error #5

Closed stephenscaff closed 3 years ago

stephenscaff commented 3 years ago

Version: 1.3.1

Details

First, thanks for this plugin. Excited to use Vite with Marko!

Using the vite-express template, nested dynamic routes (ie: .get("/product/:id", ...) cause a ENOENT error with the Marko template passed with res.marko()

The route loads, and req.params values pass, but CSS fails, and you get errors from:

Server / Vite

[vite] Internal server error: ENOENT: no such file or directory, open '.../template.marko'

Client /Console

Failed to load resource: the server responded with a status of 404 (Not Found):  .../template.marko

It seems that the loader is looking in a directory named after the defined route name. Meaning, if a route is defined as /product/:id, with the template housed at src/pages/product, the loader is searching /product/src/pages/product/template.marko.

Expected Behavior

Creating a nested dynamic route and passing a template a la @marko/express like:

.get("/product/:id", (req, res) => {
  res.marko(productTemplate, req.params);
})

should allow you to visit the dynamic route (ie: "/product/123"), with the template rendering, assets loading, and any req.params passed (ie: input.id will show 123)

NOTE

  1. With the webpack-express template, which also uses the @marko/express plugin, the above route example works as expected.

  2. With non nested dynamic routes, .get("/:id..)` it works as expected

Actual Behavior

Visiting a defined, nested, dynamic route causes file loading error. See reduced example repo, details below.

Possible Fix

Not sure yet. Most likely has to do with browserEntryQuery. Or, perhaps I just need to change a Vite config or the manifest? But, something is off with the template loader.

Additional Info ### Your Environment - Marko [Vite-Express template](https://github.com/marko-js/examples/tree/master/examples/vite-express) - Node v14.3.0 - MacOD Catalina 10.15.7 - Chrome Version 90.0.4430.212 (Official Build) (x86_64) - Link to project: [marko-vite-routing-error](https://github.com/stephenscaff/marko-vite-routing-error) ### Steps to Reproduce [Pull the reduced example repo](https://github.com/stephenscaff/marko-vite-routing-error) 1. Install and Run the project 2. Check out the routes defined in `src/index.js`. 3. Visit [http://localhost:3000/product/123](http://localhost:3000/product/123) 4. See Vite error in browser, see error in console ### Stack Trace **Server / Vite** `[vite] Internal server error: ENOENT: no such file or directory, open '/product/src/pages/product/template.marko'` **Client /Console** `Failed to load resource: the server responded with a status of 404 (Not Found): /product/src/pages/product/template.marko`
DylanPiercey commented 3 years ago

Fixed in 1.3.2, thanks for creating the reproduction and issue 😄