Turning off strict mode for babel-loader in netlify-lambda build

I have a minimal app that runs fine locally using express, but when built using netlify-lambda throws some errors related to strict mode:

ERROR in ../compiledRender/views/hello.js
Module build failed (from /netlify-test/node_modules/babel-loader/lib/index.js):
SyntaxError: /netlify-test/lib/compiledRender/views/hello.js: 'with' in strict mode (50:2)

  48 |   var __output = "";
  49 |   function __append(s) { if (s !== undefined && s !== null) __output += s }
> 50 |   with (locals || {}) {
     |   ^
  51 |     ; __append("<h1>")
  52 |     ; __append( include('includes/greeting') )
  53 |     ; __append(" from Express.js!</h1>\n")

This is the repo:

It’s choking on the compiled ejs template. Is there a way to turn off strict mode either globally or for specific files in netlify-lambda build?

Not sure about that one, @mjgs . Any chance you can easily clean up your code to comply?

If not, I’d file a feature request here to allow non-strict-mode building, but it may be closed WONTFIX in case the authors have strong opinions about strictness, which one guesses they might, based on current use of it in the codebase.

It’s not my code, it’s a compiled ejs template, perhaps I wasn’t clear about that in my original post. That’s what you see below the error message. I had to compile the template because the bundler doesn’t include non javascript files in the bundle it creates. I have since found a way to convert the ejs templates to javascript files so it’s not that important now.

Hi, @mjgs, thanks for sharing the solution you found. If there are other questions about this (or if you want to share more details about how you resolved this) please reply again anytime. I’m sure others would be curious about the details of your solution.

Sure - there is another support case were I detailed the method I used to get the templates included in the netlify-lambda bundle and how to then use them to render pages in the Netlify function:

Hopefully that is useful to others.

1 Like