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:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@alan-agius4 thanks so much! Went with option 2 and I’m not getting the error anymore.
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:
change the module target to
commonjs
Set themodule
tocommonjs
in yourtsconfig.server.json
, this however has the drawback of disabling lazy-loading on the server.set
domino
as an external dependency. Inangular.json
underserver.options
add"externalDependencies": ['domino']
, this will cause domino not to be included in your server bundle, and it will berequired
during runtime.