Rafi Henig
Rafi Henig

Reputation: 6424

"Uncaught SyntaxError: Strict mode code may not include a with statement" error after building an Angular app

I've built an application using Angular and Material, when serving the application everything worked all right, but after building, and serving the application using LiveServer on localhost and trying to browse it using Chrome, it threw the following error

Uncaught SyntaxError: Strict mode code may not include a with statement

I tried serving it with different server and the result the was same, then I browsed it using Edge and it threw this error:

SCRIPT5022: SCRIPT5022: 'with' statements are not allowed in strict mode

I know what ‘with’ is, and that is deprecated, and cannot be used along with strict mode, but could Angular (or Webpack) possibly be using ‘with’ when it’s been already deprecated? please correct me if I'm wrong on any of my assumptions.

Upvotes: 1

Views: 4688

Answers (2)

James Poulose
James Poulose

Reputation: 3833

I started seeing this error after upgrading my project to Angular 9.x and this is what got me up and running. Go to src\main.ts and comment/remove the below line

export { renderModule, renderModuleFactory } from '@angular/platform-server';

That should do it.

Upvotes: 0

anexo
anexo

Reputation: 505

As I wrote in one of my comments, it was related to one of my packages, in my case to: html-docx-js.

I uninstalled it, built the app again and it worked.

To find out which package is causing the problem, have a look at the JS code which has the issue with the "with" function and try to guess which package it is. (Most probably is an old, not supported package).

Good luck.

Upvotes: 1

Related Questions