fastify / point-of-view

Template rendering plugin for Fastify
MIT License
341 stars 86 forks source link

Deprecation warning and incorrectly rendered templates when using marko 5 #218

Closed Green-Cat closed 2 years ago

Green-Cat commented 3 years ago

🐛 Bug Report

If upgrading to Marko v5, the incorrect compiler is used. Throwing a deprecation notice.

To Reproduce

Use the latest version of marko with the latest versions of point-of-view and fastify. The following deprecation notice is shown in the console:

WARNING!!
Using `marko/compiler` has been deprecated, please upgrade to the `@marko/compiler` module.

Templates are not rendered correctly.

Expected behavior

Templates are rendered correctly and no deprecation notice is shown in the console.

Your Environment

mcollina commented 3 years ago

I'm not sure how to fix this.. Would you like to send a Pull Request to address this issue? Remember to add unit tests.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Ryuno-Ki commented 3 years ago

Is there any update on this?

Ryuno-Ki commented 3 years ago

Okay, I did some digging. But I don't know point-of-view good enough to make a recommendation where to apply a change.

First, where is the deprecation message thrown? That would be https://github.com/marko-js/marko/blob/ab1d038070e1eb23323d0b790e68489ade280c3e/packages/marko/src/compiler/index.js#L15

Introduced with https://github.com/marko-js/marko/commit/f7cbb1b5719ce767b7970ca7264a081010e8e65a#diff-b519b63eac473d4387093cd806b235ee2e9ae661a471fa623fd62efa982e6742

I would assume, around the same time, the documentation got updated to recommend the API: https://markojs.com/docs/installing/

Given that point-of-view is a fastify-plugin, @marko/build could be worth looking into (or perhaps, a template option for Fastify is needed?). https://github.com/marko-js/examples/tree/6cb92340434ed3ebd2f52eb212d9c75023582560/examples/webpack-fastify seems to be one of the templates it uses, from what I can tell after reading https://github.com/marko-js/cli/blob/c7fff31a14cf90f7c2b5905422a8698140a71197/packages/create/src/cli.js#L47

Now to the guessing part.

My assumption is, that Marko would get invoked in

https://github.com/fastify/point-of-view/blob/f218d2eaaec32a76ddbf43bac4edb6b79c6011d1/index.js#L363

which in turn would call https://github.com/marko-js/marko/blob/94992f26dbf0dd4d5378ec9f1b52b8fb81a8597d/packages/marko/src/loader/index.js#L10 which in turn invokes https://github.com/marko-js/marko/blob/94992f26dbf0dd4d5378ec9f1b52b8fb81a8597d/packages/marko/src/loader/index.js#L78 which then triggers the deprecation notice.

Can you assist, @DylanPiercey?

DylanPiercey commented 3 years ago

@Ryuno-Ki I've got a few things I'm trying to wrap up this week. I'll take a closer look at this closer to the end of the week. Thanks for notifying me 😄

YuriyTigiev commented 2 years ago

How to modify the code to solve the issue?

WARNING!! Using marko/compiler has been deprecated, please upgrade to the @marko/compiler module.

/routes/index.js

var express = require('express');
var router = express.Router();
const ccxt = require('ccxt');
var marko = require('marko');

var template = marko.load(require.resolve('../views/index.marko'));

/* GET page. */
router.get('/', async function (req, res, next) {

      template.stream(data={
          fname: "Devanshi",
          lname: "awasthi",
          host: "Vikas",
          drinks : ["Wine", "Beer", "Champagne"]})
          .pipe(res);

});

module.exports = router;
Eomm commented 2 years ago

Using marko/compiler has been deprecated, please upgrade to the @marko/compiler module.

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

DylanPiercey commented 2 years ago

I'm currently thinking it may make sense to remove Marko from point-of-view here since I don't think the API lends itself well to production use with Marko. We don't really recommend using the Marko compiler at runtime anymore outside of dev, and with that have removed the top level load api.

It can still be achieved by using the require hook, but this module adding a require hook seems awkward IMO and again would not be optimal.

We have an official Marko fastify adapter (https://github.com/marko-js/fastify) which is designed for use with precompiled templates, typically through a bundler, and I think it is a better fit. (If you want to test it you can npm init marko -- --template webpack-fastify).

Unless anyone has a good idea on how we could precompile templates while still supporting this load api I'm happy to help, but I'm somewhat stumped at the moment.

mcollina commented 2 years ago

I'm on board of removing Marko.

ovhemert commented 2 years ago

Support dropped here. Please refer to https://github.com/marko-js/fastify for the alternative. Issue can be closed.