tbuckham
tbuckham

Reputation: 11

ejs issues loading htmlWebpackPlugin (is not defined)

I have what I believe is an ejs issue, and having cloned a github repo and not really used ejs before I'm having some issues. Strangely I can get the repo to work on local host, but in the IDE I get the following:

ReferenceError: /home/cabox/workspace/example/base.html:10
    8|   <body>
    9|     <div id="page"></div>
 >> 10|     <script src="<%= htmlWebpackPlugin.options.libBaseUrl 
%>/llsRecorder-v1.0.0.js"></script>
    11|   </body>
    12| </html>
    13| 

htmlWebpackPlugin is not defined
    at eval (eval at <anonymous>     (/home/cabox/workspace/node_modules/ejs/lib/ejs.js:524:12), <anonymous>:11:26)    
at returnedFn (/home/cabox/workspace/node_modules/ejs/lib/ejs.js:555:17)
    at tryHandleCache     (/home/cabox/workspace/node_modules/ejs/lib/ejs.js:203:34)
    at View.exports.renderFile [as engine]     (/home/cabox/workspace/node_modules/ejs/lib/ejs.js:412:10)
    at View.render     (/home/cabox/workspace/node_modules/express/lib/view.js:128:8)
    at tryRender     (/home/cabox/workspace/node_modules/express/lib/application.js:640:10)
    at EventEmitter.render     (/home/cabox/workspace/node_modules/express/lib/application.js:592:3)
    at ServerResponse.render     (/home/cabox/workspace/node_modules/express/lib/response.js:971:7)
    at /home/cabox/workspace/server.js:14:9
    at Layer.handle [as handle_request]     (/home/cabox/workspace/node_modules/express/lib/router/layer.js:95:5)

I've installed the latest version of ejs with npm and setup my views as so (which works with local host):

app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/example');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');

app.get('/', function(req, res, next) {
res.render("base");
});

Any idea what could be going wrong between the local host on the IDE version? Something obvious such as 'public' being changed to the IDE folder name perhaps, or something equally small.

Thanks!

Tom

Upvotes: 0

Views: 2004

Answers (1)

Wright
Wright

Reputation: 3424

You have to pass the variable to the render in the form of an object. The variable you're passing also has to exist in that same file either by requireing it or defining it there.(I don't exactly know how you're set up)

app.get('/', function(req, res, next) {
    res.render("base", {htmlWebpackPlugin: htmlWebpackPlugin});
});

Upvotes: 1

Related Questions