<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Manoj Sridhar</title>
    <description>The latest articles on DEV Community by Manoj Sridhar (@manoj_sridhar_f7e0d9b4794).</description>
    <link>https://dev.to/manoj_sridhar_f7e0d9b4794</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2546671%2F973f6027-debf-4c3c-a444-bb9f93e5c3fb.jpg</url>
      <title>DEV Community: Manoj Sridhar</title>
      <link>https://dev.to/manoj_sridhar_f7e0d9b4794</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/manoj_sridhar_f7e0d9b4794"/>
    <language>en</language>
    <item>
      <title>ZoneJs Error Using Angular 18 with MVC Project</title>
      <dc:creator>Manoj Sridhar</dc:creator>
      <pubDate>Fri, 07 Feb 2025 15:03:09 +0000</pubDate>
      <link>https://dev.to/manoj_sridhar_f7e0d9b4794/zonejs-error-using-angular-18-with-mvc-project-49e1</link>
      <guid>https://dev.to/manoj_sridhar_f7e0d9b4794/zonejs-error-using-angular-18-with-mvc-project-49e1</guid>
      <description>&lt;p&gt;I have a project that uses MVC .cshtml pages and use Angular components loaded in razor pages either with &lt;code&gt;script&lt;/code&gt; tag or using &lt;code&gt;iFrame&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;We had been using Angular 5 before and loaded the scripts as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script type="text/javascript" src="@Url.Content("~/dist/polyfills.bundle.js")"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript" src="@Url.Content("~/dist/main.bundle.js")"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we started converted it to Angular 18 and I tried to use the same pattern. Created new angular project using Angular cli.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ng new upgraded-angular&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After doing &lt;code&gt;ng build&lt;/code&gt; with default &lt;code&gt;production&lt;/code&gt; configuration, I was using the following script to load the project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script type="text/javascript" src="@Url.Content("~/dist/upgraded-angular/browser/polyfills.js")"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript" src="@Url.Content("~/dist/upgraded-angular/browser/main.js")"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gave me the below error and the component was not loaded &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;zone.js has detected that ZoneAwarePromise (window|global).Promise has been overwritten only when optimization is true. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Angular cli has correctly added zone.js to pollyfills as below in angular.json.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"polyfills": [
              "zone.js"
            ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I tried all the steps in online but nothing worked. I figured out that the same worked fine when I do &lt;code&gt;npm run watch&lt;/code&gt; which is running the build in &lt;code&gt;development&lt;/code&gt; configuration. Also found in &lt;code&gt;production&lt;/code&gt; configuration, if I used &lt;code&gt;Optimization:false&lt;/code&gt;, the error was not happening.&lt;/p&gt;

&lt;p&gt;Later I found the culprit to be the &lt;code&gt;type&lt;/code&gt; that we use to load the script. Due to the adoption of ES modules by angular recent versions, we had to use &lt;code&gt;type="module"&lt;/code&gt; for the script files. I changed my script to below and then I am now able to load angular 18 components in mvc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script type="module" src="@Url.Content("~/dist/upgraded-angular/browser/polyfills.js")"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="module" src="@Url.Content("~/dist/upgraded-angular/browser/main.js")"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>angular</category>
      <category>mvc</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
