Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Green-Cat opened this issue Mar 20, 2021 · 10 comments
Closed

Comments

@Green-Cat
Copy link

🐛 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

  • node version: 15
  • fastify version: >=3.14.0
  • marko version: 5.5.2
  • os: Mac
@mcollina
Copy link
Member

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
Copy link

stale bot commented Jun 26, 2021

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.

@stale stale bot added the stale label Jun 26, 2021
@Ryuno-Ki
Copy link

Is there any update on this?

@stale stale bot removed the stale label Jul 11, 2021
@Ryuno-Ki
Copy link

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 marko-js/marko@f7cbb1b#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

const template = opts && opts.templateSrc ? engine.load(join(templatesDir, page), opts.templateSrc) : engine.load(join(templatesDir, page))

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
Copy link

@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
Copy link

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
Copy link
Member

Eomm commented Dec 14, 2021

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
Copy link

DylanPiercey commented Dec 14, 2021

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
Copy link
Member

I'm on board of removing Marko.

@ovhemert ovhemert mentioned this issue Dec 16, 2021
4 tasks
@ovhemert
Copy link
Contributor

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

@simoneb simoneb closed this as completed Dec 22, 2021
titanism added a commit to ladjs/consolidate that referenced this issue Jun 9, 2023
…or API changes in v8, removed support for razor-tmpl removed marko support (per <fastify/point-of-view#218>), fixed try/catch issues (per <tj#341>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants