Angular 12 Universal Configuration ‘development’ is not set in the workspace in Angular Universal
Explanation of the problem
A new Angular 11 project named “client” was created and then upgraded to Angular version 12. The @nguniversal/express-engine package was installed using the command “ng add @nguniversal/express-engine”. Attempts to run the Universal Angular using “npm run dev:ssr” resulted in an error, with the following message:
“firstname.lastname@example.org dev:ssr ng run client:serve-ssr”
“Configuration ‘development’ is not set in the workspace. npm ERR! code 1 npm ERR! path E:\PRACTICE\MYPETPROJECTS\tanechka\client npm ERR! command failed npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c ng run client:serve-ssr”
A complete log of this error can be found in the file located at: “C:\Users\1\AppData\Local\npm-cache_logs\2021-06-08T14_35_07_681Z-debug.log”
The provided “angular.json” file is included for reference.
Troubleshooting with the Lightrun Developer Observability Platform
Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.
- Instantly add logs to, set metrics in, and take snapshots of live applications
- Insights delivered straight to your IDE or CLI
- Works where you do: dev, QA, staging, CI/CD, and production
Problem solution for Angular 12 Universal Configuration ‘development’ is not set in the workspace in Angular Universal
The issue of server-side rendering (SSR) in Angular version 12 is that if a development configuration is used, it tries to use the same configuration for both the server and the build. This can result in problems and issues.
One potential solution to this issue is to use the new experimental way of SSR by using the command “ng add @nguniversal/common”. This allows users to opt-in to the new experimental SSR method, which can potentially solve the issue with the development configuration.
The “ng add @nguniversal/common” command allows users to add the necessary dependencies and configurations for SSR, as well as set up the required configuration files. This solution is particularly useful for those who are looking to use SSR in their Angular projects and want to avoid any potential issues that may arise with the use of a development configuration.
Other popular problems with Angular Universal
Problem: Issues with the Development Configuration
One of the common problems faced by Angular Universal users is issues with the development configuration. By default, the same configuration is used for both the server and the build. However, this can result in issues when certain configurations are not present in both the server and build. As a result, users may face issues with server-side rendering and other Angular Universal related functionalities.
One way to resolve this issue is to delete the line “defaultConfiguration”: “development” from the “serve-ssr” file. This should be followed by adding options such as “browserTarget”: “client:build” and “serverTarget”: “client:server” to the builder. This will help ensure that different configurations are used for the server and build, reducing the likelihood of encountering issues with Angular Universal.
Problem: Incomplete Migrations to Production-by-default
Another common problem faced by Angular Universal users is incomplete migrations to production-by-default. When users use the “ng update @angular/cli –migrate-only production-by-default” command, their projects are converted to production by default, but this also creates a development configuration. This can result in issues with Angular Universal as it relies on a production-by-default configuration.
To resolve this issue, users should ensure that their migrations to production-by-default are complete and do not include any remnants of the development configuration. This can be done by thoroughly reviewing their project configuration and making any necessary changes to ensure that it is aligned with a production-by-default configuration.
Problem: Lack of Support for the Latest Angular Versions
A third common problem faced by Angular Universal users is the lack of support for the latest Angular versions. As Angular is constantly evolving, it is common for users to encounter issues when using older versions of Angular Universal with the latest Angular versions. This can result in compatibility issues and a lack of access to the latest Angular Universal features.
To resolve this issue, users should ensure that they are using the latest version of Angular Universal that is compatible with the latest version of Angular. This can be done by regularly checking for updates and upgrading to the latest version of Angular Universal whenever necessary. Additionally, users can opt-in to the new experimental server-side rendering method in Angular version 12 by using the “ng add @nguniversal/common” command.
A brief introduction to Angular Universal
Angular Universal is a technology that allows for server-side rendering of Angular applications. This is achieved by running the Angular application on the server, rather than in the client browser, and returning the fully rendered application to the client. Angular Universal is particularly useful for improving the initial loading time and SEO of Angular applications.
Most popular use cases for Angular Universal
- Server-side rendering (SSR) of Angular applications: Angular Universal allows developers to render Angular applications on the server, which can improve the loading performance and provide a better user experience, especially for slower networks and low-end devices. The server-side rendering process can be performed using the Angular Universal package, which can be added to an existing Angular project using the following command:
ng add @nguniversal/common
- Improved search engine optimization (SEO): With Angular Universal, developers can ensure that the content of their applications is fully indexed by search engines, which can improve the visibility of the applications in search results and attract more traffic. Angular Universal enables developers to generate a static HTML version of their applications on the server, which can be easily crawled by search engines.
It’s Really not that Complicated.
You can actually understand what’s going on inside your live applications. It’s a registration form away.