{"id":1308,"date":"2015-03-17T07:07:49","date_gmt":"2015-03-17T07:07:49","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=1308"},"modified":"2015-08-06T12:25:37","modified_gmt":"2015-08-06T12:25:37","slug":"options-found-in-locals-object-in-ejs","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/stack-overflow\/options-found-in-locals-object-in-ejs\/","title":{"rendered":"Options found in locals object in ejs"},"content":{"rendered":"<p><a href=\"http:\/\/stackoverflow.com\/users\/534755\/nikola\"><img loading=\"lazy\" decoding=\"async\" title=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" src=\"http:\/\/stackoverflow.com\/users\/flair\/534755.png\" rel=\"lightbox[1308]\" alt=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" width=\"208\" height=\"58\" \/><\/a><br \/>\nI&#8217;m a big fan of <a href=\"http:\/\/stackoverflow.com\/\">Stack Overflow<\/a> and I tend to contribute regularly (am currently in the <a href=\"http:\/\/stackexchange.com\/leagues\/1\/alltime\/stackoverflow\/2008-07-31\/534755?sort=reputationchange#534755\">top 0.X%<\/a>).\u00a0In this category (<a href=\"http:\/\/www.nikola-breznjak.com\/blog\/category\/stack-overflow\/\">stackoverflow<\/a>)\u00a0of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread <a href=\"http:\/\/meta.stackoverflow.com\/questions\/266971\/can-i-post-so-questions-and-answers-in-a-personal-blog\/266973\">here<\/a>.<\/p>\n<p>My <a href=\"http:\/\/stackoverflow.com\/questions\/28063407\/options-found-in-locals-object-in-ejs\">question<\/a> was:<\/p>\n<p>I got the following error when running the project from\u00a0<a style=\"color: #0c65a5;\" href=\"https:\/\/github.com\/Hitman666\/MEAN_MVC_2ndTutorial\" rel=\"nofollow\">GitHub<\/a>: &#8220;options found in locals object. The option(s) is copied to the option object. This behavior is deprecated and will be removed in EJS 3&#8221;<\/p>\n<p>I tried to update the ejs and express modules to the newest versions but the notice persists. I googled, ofc, and the only thread about it is\u00a0<a style=\"color: #0c65a5;\" href=\"https:\/\/github.com\/mde\/ejs\/issues\/36\" rel=\"nofollow\">this<\/a>, but it doesn&#8217;t help.<\/p>\n<p>Does anyone know more about this?<\/p>\n<p>For reference, here is the whole important code:<\/p>\n<p><em>app\/views\/index.ejs<\/em><\/p>\n<pre class=\"lang:default decode:true\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n    &lt;title&gt;&lt;%= title %&gt;&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n    &lt;h1&gt;&lt;%= title %&gt;&lt;\/h1&gt;\r\n    &lt;img src=\"img\/logo.jpg\" alt=\"Hack Hands logo\"&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><em>app\/controllers\/index.server.controller.js<\/em><\/p>\n<pre class=\"lang:default decode:true\">exports.render = function(req, res) {\r\n    res.render('index', {\r\n        title: 'MEAN MVC'\r\n    });\r\n};<\/pre>\n<p><em>app\/routes\/index.server.route.js<\/em><\/p>\n<pre class=\"lang:default decode:true\">module.exports = function(app) {\r\n    var index = require('..\/controllers\/index.server.controller');\r\n    app.get('\/', index.render);\r\n};<\/pre>\n<p><em>app\/config\/express.js<\/em><\/p>\n<pre class=\"lang:default decode:true\">var express = require('express');\r\nmodule.exports = function() {\r\n    var app = express();\r\n\r\n    app.set('views', '.\/app\/views');\r\n    app.set('view engine', 'ejs');\r\n\r\n    require('..\/app\/routes\/index.server.routes.js')(app);\r\n\r\n    app.use(express.static('.\/public'));\r\n\r\n    return app;\r\n};<\/pre>\n<p><em>server.js<\/em><\/p>\n<pre class=\"lang:default decode:true\">var port = 1337;\r\nvar express = require('.\/config\/express');\r\nvar app = express();\r\napp.listen(port);\r\nmodule.exports = app;\r\nconsole.log('Server running at http:\/\/localhost:' + port);<\/pre>\n<p style=\"color: #222222;\">The answer, by <a href=\"http:\/\/stackoverflow.com\/users\/1937836\/timothy-gu\">Timothy Gu<\/a>, was:<\/p>\n<blockquote>\n<div class=\"post-text\">\n<p>tl;dr: Upgrade to the latest version of EJS. It removes all warnings about\u00a0<code>options<\/code>\u00a0and\u00a0<code>locals<\/code>.<\/p>\n<h2 style=\"font-weight: normal;\"><code>whoami<\/code><\/h2>\n<p>I&#8217;m a collaborator (or\u00a0<em>the<\/em>\u00a0collaborator in @micnic&#8217;s comment above) in EJS v2. I only started maintaining EJS after version 2.0.3 (or something like that) was released, so I don&#8217;t know a lot about how the API changes took place.<\/p>\n<h2 style=\"font-weight: normal;\">History<\/h2>\n<p>EJS v2&#8217;s\u00a0<code>renderFile<\/code>\u00a0function, used by Express.js, now has the signature<\/p>\n<pre class=\"lang:default decode:true\">function(path[, options[, locals]], cb)<\/pre>\n<p>But for compatibility with and Express.js, which calls all functions as<\/p>\n<pre class=\"lang:default decode:true  \">function(path, locals, cb)<\/pre>\n<p>with options mixed into the\u00a0<code>locals<\/code>\u00a0object, EJS automatically picks out the locals with option-y names and treat them as options.<\/p>\n<p>But because the Express.js signature is also the function signature of EJS v1, we also print a warning if any option in\u00a0<code>locals<\/code>\u00a0is copied to\u00a0<code>options<\/code>, urging developers to use the new signature with\u00a0<code>locals<\/code>\u00a0and\u00a0<code>options<\/code>\u00a0separated (it was actually\u00a0<a style=\"color: #0c65a5;\" href=\"https:\/\/github.com\/mde\/ejs\/commit\/0d3c2bfdfa84a32ba9bb9d52471365f368b9c4ba\" rel=\"nofollow\">me who added the warning<\/a>).<\/p>\n<p>However, Express.js users do not have a choice in terms of calling convention, so the warning is always present in Express.js.<\/p>\n<p>Some users did complain:\u00a0<a style=\"color: #0c65a5;\" href=\"https:\/\/github.com\/mde\/ejs\/issues\/34\" rel=\"nofollow\">#34<\/a>\u00a0<a style=\"color: #0c65a5;\" href=\"https:\/\/github.com\/mde\/ejs\/issues\/36\" rel=\"nofollow\">#36<\/a>.<\/p>\n<p>At first, @mde (who is the main maintainer of EJS) pushed a\u00a0<a style=\"color: #0c65a5;\" href=\"https:\/\/github.com\/mde\/ejs\/commit\/3134613044c4b11852dc250ff4d52705cf54ede5\" rel=\"nofollow\">fix<\/a>, which correctly disables warnings on Express.js, and Express.js only.<\/p>\n<p>But then, the person in #36 still complained, as he was using\u00a0<a style=\"color: #0c65a5;\" href=\"https:\/\/github.com\/mde\/ejs\/commit\/a3cd2c8508ef39cb998add20ec96a25141023328#commitcomment-9433188\" rel=\"nofollow\"><code>filename<\/code>\u00a0as the name of a local<\/a>, and when the optiony local is copied to\u00a0<code>options<\/code>\u00a0a warning is printed.<\/p>\n<p>At last, @mde was like &#8220;f*** this shit&#8221; and\u00a0<a style=\"color: #0c65a5;\" href=\"https:\/\/github.com\/mde\/ejs\/commit\/cc0c814b7000d91ba72e5ae8ae09609bb573a311\" rel=\"nofollow\">removed all the deprecation warnings<\/a>, including an uncontroversial and legitimate one, and released version 2.2.4 (the legitimate warning was\u00a0<a style=\"color: #0c65a5;\" href=\"https:\/\/github.com\/mde\/ejs\/commit\/c83bf2ea9ffefe9f4b60429a17bd5e730421f776\" rel=\"nofollow\">restored by me<\/a>\u00a0after the release).<\/p>\n<h2 style=\"font-weight: normal;\">Future<\/h2>\n<p>@dougwilson (an Express.js maintainer) said he was\u00a0<a style=\"color: #0c65a5;\" href=\"https:\/\/github.com\/strongloop\/express\/pull\/2237#issuecomment-70397959\" rel=\"nofollow\">interested<\/a>\u00a0in a separation of\u00a0<code>options<\/code>\u00a0and\u00a0<code>locals<\/code>\u00a0in Express.js v5, just like in EJS v2. I did volunteer to make that change, but then I got busy so yeah.<\/p>\n<\/div>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%).\u00a0In this category (stackoverflow)\u00a0of posts I will will be posting&hellip;<\/p>\n","protected":false},"author":1,"featured_media":609,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-1308","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stack-overflow"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=1308"}],"version-history":[{"count":2,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1308\/revisions"}],"predecessor-version":[{"id":1687,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1308\/revisions\/1687"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/609"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=1308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=1308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=1308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}