question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular SSR run fails with Module parse failed: 'with' in strict mode

See original GitHub issue

🐞 bug report

Description

I’m trying to build & run my Angular SSR (Angular Universal) app, whereas the 3rd script fails:

ng run web:build --configuration=production
ng run web:server --configuration=production
ng run web-ssr:serve

With the below error.

🔥 Exception or Error


ERROR in ./dist/apps/web/server/main.js 178387:16
Module parse failed: 'with' in strict mode (178387:16)
File was processed with these loaders:
 * ./node_modules/ts-loader/index.js
You may need an additional loader to handle the result of these loaders.
|                 if (file)
|                     code += '\n//@ sourceURL=' + file;
>                 with (this)
|                     eval(code);
|             },
There was an error with the build. See above.
/Users/user/project/dist/apps/web-ssr/main.js was not restarted.

🌍 Your Environment

Angular Version:


@angular-devkit/architect                  0.900.7
@angular-devkit/build-angular              0.901.6
@angular-devkit/build-optimizer            0.901.6
@angular-devkit/build-webpack              0.901.11
@angular-devkit/core                       9.1.6
@angular-devkit/schematics                 9.1.6
@angular/cdk                               9.2.3
@angular/cli                               9.1.6
@angular/fire                              6.0.0
@angular/material                          9.2.3
@angular/platform-server                   9.1.12
@ngtools/webpack                           9.1.6
@nguniversal/common                        10.0.1
@nguniversal/express-engine                10.0.1
@nguniversal/module-map-ngfactory-loader   8.2.6
@schematics/angular                        9.1.11
@schematics/update                         0.901.6
rxjs                                       6.5.5
typescript                                 3.8.3
webpack                                    4.42.0

Anything else relevant? My server bundle target is es2015.

I’ve tried the solution proposed in #35327 but it didn’t resolve the issue.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
matthiasuntcommented, Aug 6, 2020

@alan-agius4 thanks so much! Went with option 2 and I’m not getting the error anymore.

1reaction
alan-agius4commented, Aug 6, 2020

Hi @muzammalrahim,

The problem is that some parts of domino are require JS to be in sloppy mode but ES2015 modules are always strict.

There are 2 possible workaround for this:

  1. change the module target to commonjs Set the module to commonjs in your tsconfig.server.json, this however has the drawback of disabling lazy-loading on the server.

  2. set domino as an external dependency. In angular.json under server.options add "externalDependencies": ['domino'], this will cause domino not to be included in your server bundle, and it will be required during runtime.

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack2: Module parse failed -> 'with' in strict mode #1939
It seems that code which compiles to a with statement causes module parsing to fail. in webpack-2.0.5-beta. Any idea why this is?
Read more >
Upgraded From Angular 9 to 14 - build:ssr leads to Module ...
after many updates to dependencies, I have been able to transpile the application just fine and run it locally via ng serve and...
Read more >
angular/universal - Gitter
When I'm running SSR, im getting an error strict mode code may not contain 'with' statements from the domino package (looked where exactly)....
Read more >
module parse failed: unexpected token (1:0) you may need an ...
1 Answer. Sorted by: 7. Apparently it happened because you have two module properties in the webpack config object. Given JS objects can...
Read more >
rollup.js
onError <cmd> Shell command to run on `"ERROR"` event --validate Validate output. The flags listed below are only available via the command line...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found