Marko Taglib: Cannot read property 'replace' of undefined
Marko Version: 5.14.2
Details
If I render a marko template I got the error below from marko taglib
application.js:630 TypeError: Cannot read property 'replace' of undefined
at render (/projectPath/node_modules/@lasso/marko-taglib/taglib/slot-tag.js:92:57)
at render (/projectPath/node_modules/@lasso/marko-taglib/taglib/head-tag.js:16:3)
at renderTagHelper (/projectPath/node_modules/marko/dist/runtime/helpers/render-tag.js:15:77)
at _marko_template._.t (/projectPath/.../login/index.marko:44:26)
at renderer (/projectPath/node_modules/marko/dist/runtime/components/renderer.js:218:5)
at safeRender (/projectPath/node_modules/marko/dist/runtime/renderable.js:7:5)
at Template.render (/projectPath/node_modules/marko/dist/runtime/renderable.js:139:14)
at ServerResponse.renderMarkoTemplate [as marko] (/projectPath/node_modules/@marko/express/dist/cjs/index.js:20:10)
at AuthenticationRouter.<anonymous> (/projectPath/.../AuthenticationRouter.js:86:29)
I use require('@marko/compiler/register'); to load marko template and then I require the template via const template = require(templatePath).default;
And then I do res.marko(template, {...} to render and send it to the client.
Your Environment
NodeJS 16.6.1 "@lasso/marko-taglib": "^2.0.3", "@marko/express": "^1.0.0", "lasso": "^3.4.0", "lasso-less": "^4.0.0", "lasso-marko": "^3.0.1", "lasso-minify": "1.0.4", "lasso-minify-css": "1.1.4", "marko": "^5.14.2",
Is there something missing or I'm doing something wrong?
In Marko 4 it works fine. Could it depent on the change from node-require to @marko/compiler/register?
I am having the same issue. When updating to Marko 5 I get the console warning message:
Using "marko/node-require" has been replaced with "@marko/compiler/register".
So I changed marko/node-require to @marko/compiler/register.
Now I get a warning that says:
Using "marko/compiler" has been deprecated, please upgrade to the "@marko/compiler" module.
Even though I am using @marko/compiler...
After making that change and loading a page I get the error: TypeError: Cannot read property 'replace' of undefined
@JPritchard9518 @hedav85 it turns out that @lasso/marko-taglib is relying on some meta data being attached to the template that is not added via the newer @marko/compiler/register by default.
You can opt into adding that meta data again by using:
require("@marko/compiler/register")({ meta: true })
I do think we should figure out a better way to do this in @lasso/marko-taglib though.
@DylanPiercey with the meta flag it works :+1: So the issue is solved for me.