This article is about fixing Angular 12 Universal Configuration 'development' is not set in the workspace
  • 05-Feb-2023
Lightrun Team
Author Lightrun Team
Share
This article is about fixing Angular 12 Universal Configuration 'development' is not set in the workspace

Angular 12 Universal Configuration ‘development’ is not set in the workspace in Angular Universal

Lightrun Team
Lightrun Team
05-Feb-2023

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:

“client@0.0.0 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

Start for free today

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.

Solution:

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.

Solution:

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.

Solution:

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.

The Angular Universal implementation involves the use of Node.js on the server to run the Angular application, with the server generating the HTML, CSS, and JavaScript that make up the application. This HTML, CSS, and JavaScript is then sent to the client, where the application is fully loaded and ready for use, with no additional server-side requests required. The Angular Universal technology integrates seamlessly with Angular, allowing developers to build and maintain a single codebase for both client and server-side rendering. This allows for a more efficient and streamlined development process, as well as improved performance and user experience for end-users.

Most popular use cases for Angular Universal

  1. 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
  1. 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.
  2. Enhancing the performance of Angular applications: Angular Universal allows developers to improve the performance of their applications by reducing the time to first paint, which can enhance the user experience and increase user engagement. The server-side rendering process can reduce the amount of JavaScript that needs to be executed on the client-side, which can result in faster loading times, especially for low-end devices. Additionally, Angular Universal enables developers to implement advanced performance optimization techniques, such as lazy-loading and code-splitting, which can further improve the performance of their applications.
Share

It’s Really not that Complicated.

You can actually understand what’s going on inside your live applications.

Try Lightrun’s Playground

Lets Talk!

Looking for more information about Lightrun and debugging?
We’d love to hear from you!
Drop us a line and we’ll get back to you shortly.

By submitting this form, I agree to Lightrun’s Privacy Policy and Terms of Use.