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

**URL:** <https://answers.netlify.com/t/turning-off-strict-mode-for-babel-loader-in-netlify-lambda-build/10959>\
**Category:** Support\
**Tags:** lambda-functions\
**Created:** [March 21, 2020, 10:55pm UTC](https://answers.netlify.com/t/turning-off-strict-mode-for-babel-loader-in-netlify-lambda-build/10959 "2020-03-21T22:55:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjgs](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mjgs](https://answers.netlify.com/u/mjgs)\
**Post date:** [March 21, 2020, 10:55pm UTC](https://answers.netlify.com/t/turning-off-strict-mode-for-babel-loader-in-netlify-lambda-build/10959/1 "2020-03-21T22:55:31Z")

</div>

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

```auto
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:

[https://github.com/mjgs-linkblog/netlify-test](https://github.com/mjgs-linkblog/netlify-test)

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?

---

<div class="post-metadata">

**Author:** ![fool](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fool/32/37_2.png) [@fool](https://answers.netlify.com/u/fool)\
**Post date:** [March 24, 2020, 3:57pm UTC](https://answers.netlify.com/t/turning-off-strict-mode-for-babel-loader-in-netlify-lambda-build/10959/2 "2020-03-24T15:57:18Z")

</div>

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.

> **[Issues · netlify/netlify-lambda](https://github.com/netlify/netlify-lambda/issues)**
>
> Helps building and serving lambda functions locally and in CI environments - Issues · netlify/netlify-lambda

---

<div class="post-metadata">

**Author:** ![mjgs](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mjgs](https://answers.netlify.com/u/mjgs)\
**Post date:** [March 24, 2020, 5:56pm UTC](https://answers.netlify.com/t/turning-off-strict-mode-for-babel-loader-in-netlify-lambda-build/10959/3 "2020-03-24T17:56:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![luke](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/luke/32/39_2.png) [@luke](https://answers.netlify.com/u/luke)\
**Post date:** [March 26, 2020, 7:46am UTC](https://answers.netlify.com/t/turning-off-strict-mode-for-babel-loader-in-netlify-lambda-build/10959/4 "2020-03-26T07:46:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mjgs](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mjgs](https://answers.netlify.com/u/mjgs)\
**Post date:** [March 26, 2020, 9:34am UTC](https://answers.netlify.com/t/turning-off-strict-mode-for-babel-loader-in-netlify-lambda-build/10959/5 "2020-03-26T09:34:54Z")

</div>

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:

> [@\_\_dirname appears to be incorrectly set in lambda function](https://answers.netlify.com/t/dirname-appears-to-be-incorrectly-set-in-lambda-function/10691/7):
>
> Yeah I discovered this though a similar approach using a nodejs directory listing library. During the static build the directory is something like /opt/build/repo/\_site but then in the function this changes to /mnt/task. I took a different approach - I found a way to convert the ejs templates into javascript files: module.exports = ` \<html\>\<%= somevariable %\>\</html\> `; I then require these in the app, render the html and send back to the client. Since the files are javascript files, they get …

Hopefully that is useful to others.
