<?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: Todd Palmer</title>
    <description>The latest articles on DEV Community by Todd Palmer (@tpalmer).</description>
    <link>https://dev.to/tpalmer</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%2F160365%2F008aa9d8-8e27-49c7-a4ab-ea98fa57a2f1.png</url>
      <title>DEV Community: Todd Palmer</title>
      <link>https://dev.to/tpalmer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tpalmer"/>
    <language>en</language>
    <item>
      <title>npm Peer Dependencies for the Professional Developer</title>
      <dc:creator>Todd Palmer</dc:creator>
      <pubDate>Mon, 14 Oct 2024 01:30:16 +0000</pubDate>
      <link>https://dev.to/tpalmer/npm-peer-dependencies-for-the-professional-developer-36m2</link>
      <guid>https://dev.to/tpalmer/npm-peer-dependencies-for-the-professional-developer-36m2</guid>
      <description>&lt;p&gt;In this article, I clarify what &lt;strong&gt;npm Peer Dependencies&lt;/strong&gt; are and especially when you should use them. &lt;strong&gt;Peer Dependencies&lt;/strong&gt; are listed in your project's &lt;code&gt;package.json&lt;/code&gt; file in the &lt;code&gt;peerDependencies&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;To get the most out of this article you should have at least an introductory understanding of &lt;a href="https://www.npmjs.com/" rel="noopener noreferrer"&gt;npm&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contents
&lt;/h2&gt;

&lt;p&gt;In this article:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We will &lt;strong&gt;compare&lt;/strong&gt; exactly how Peer Dependencies work versus regular Dependencies.&lt;/li&gt;
&lt;li&gt;We will look at some &lt;strong&gt;examples&lt;/strong&gt; of both Peer Dependencies and Dependencies.&lt;/li&gt;
&lt;li&gt;Then, we will examine how npm handles &lt;strong&gt;version conflicts&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Finally, having the fundamentals solidly in our grasp, we will lay out an approach to &lt;strong&gt;deciding when Peer Dependencies are appropriate&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Scenario
&lt;/h2&gt;

&lt;p&gt;To keep it real, let’s assume you’re creating an Angular or React Component Library or even just a simple JavaScript file that exports some functions.&lt;/p&gt;

&lt;p&gt;Your project relies on packages from the &lt;a href="https://www.npmjs.com/" rel="noopener noreferrer"&gt;npm Registry&lt;/a&gt;. These packages are your project’s &lt;strong&gt;dependencies&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You want to create your own &lt;strong&gt;npm package&lt;/strong&gt; from your project. So you use &lt;code&gt;npm pack&lt;/code&gt; to generate an &lt;strong&gt;npm package&lt;/strong&gt; from your project. You might even decide to publish it to the &lt;a href="https://www.npmjs.com/" rel="noopener noreferrer"&gt;npm Registry&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Other teams could then find your component library as a &lt;strong&gt;package&lt;/strong&gt; on the &lt;a href="https://www.npmjs.com/" rel="noopener noreferrer"&gt;npm Registry&lt;/a&gt;. They can use &lt;code&gt;npm install&lt;/code&gt; to add your package as a dependency in their own projects. We use &lt;strong&gt;Dependencies&lt;/strong&gt; and &lt;strong&gt;Peer Dependencies&lt;/strong&gt; in &lt;code&gt;package.json&lt;/code&gt; to tell these other projects what packages also need to be added for our component library to work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dependencies Versus Peer Dependencies
&lt;/h2&gt;

&lt;p&gt;At their most basic level here is how &lt;strong&gt;Dependencies&lt;/strong&gt; and &lt;strong&gt;Peer Dependencies&lt;/strong&gt; work:&lt;/p&gt;

&lt;h3&gt;
  
  
  Dependencies
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://docs.npmjs.com/cli/v10/configuring-npm/package-json#dependencies" rel="noopener noreferrer"&gt;Dependencies&lt;/a&gt; are listed in your project's &lt;code&gt;package.json&lt;/code&gt; file in a &lt;code&gt;dependencies&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;When you add a package in your code's &lt;code&gt;dependencies&lt;/code&gt;, you are saying:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My code needs this package to run.&lt;/li&gt;
&lt;li&gt;If this package doesn’t already exist in my &lt;code&gt;node_modules&lt;/code&gt; directory, then add it automatically.&lt;/li&gt;
&lt;li&gt;Furthermore, add any packages that are listed in this package’s &lt;code&gt;dependencies&lt;/code&gt;. These packages are called &lt;strong&gt;Transitive Dependencies&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Peer Dependencies
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependencies" rel="noopener noreferrer"&gt;Peer Dependencies&lt;/a&gt; are listed in your project's &lt;code&gt;package.json&lt;/code&gt; file in a &lt;code&gt;peerDependencies&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;By adding a package in your code's &lt;code&gt;peerDependencies&lt;/code&gt; you are saying:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My code is compatible with this version of the package.&lt;/li&gt;
&lt;li&gt;If this package already exists in node_modules, do nothing.&lt;/li&gt;
&lt;li&gt;If this package doesn’t already exist in the node_modules directory or it is the wrong version, don’t add it. But, show a warning to the user that it wasn’t found.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Adding Dependencies
&lt;/h2&gt;

&lt;p&gt;So, we add dependencies in the &lt;strong&gt;package.json&lt;/strong&gt; file of our npm package folder. Let’s look at exactly how we add packages as dependencies and some examples of package dependencies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding a Dependency
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Dependency&lt;/strong&gt; is an npm package that our code depends on in order to be able to run. Some popular packages that can be added as dependencies are &lt;a href="https://www.npmjs.com/package/lodash" rel="noopener noreferrer"&gt;lodash&lt;/a&gt;, &lt;a href="https://d3js.org/" rel="noopener noreferrer"&gt;D3&lt;/a&gt;, and &lt;a href="https://www.chartjs.org/" rel="noopener noreferrer"&gt;chartjs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We add a regular dependency like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install lodash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;npm adds the package name and version to the dependencies object in our project’s &lt;strong&gt;package.json&lt;/strong&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"dependencies": {
  "lodash": "^4.17.11"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some of you might remember the old days when we had to use the --save flag to get npm to update the &lt;code&gt;dependencies&lt;/code&gt; in &lt;strong&gt;package.json&lt;/strong&gt;. Thankfully, we don’t need to do that anymore.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding a Peer Dependency
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Peer Dependencies&lt;/strong&gt; are used to specify that our project is compatible with a specific version of an npm package. Good examples are &lt;a href="https://angular.dev/" rel="noopener noreferrer"&gt;Angular&lt;/a&gt; and &lt;a href="https://react.dev/" rel="noopener noreferrer"&gt;React&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To add a &lt;strong&gt;Peer Dependency&lt;/strong&gt; you actually need to manually modify your &lt;strong&gt;package.json&lt;/strong&gt; file. For example, for component library projects, depending on which framework you are using I recommend adding &lt;strong&gt;angular/core&lt;/strong&gt; or &lt;strong&gt;react&lt;/strong&gt; as a peer dependency.&lt;/p&gt;

&lt;p&gt;So if you wanted to specify that your package is built for React 18, you could include something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"peerDependencies": {
   "react": "^18.0.0",
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or maybe you want to say that you have tested your component library with both Angular version 17 and 18 but not 19 because it wasn't out yet. Then you could use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"peerDependencies": {
   "@angular/core": "&amp;gt;=17.0.0 || &amp;lt;19"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  About Conflicts
&lt;/h2&gt;

&lt;p&gt;I get a lot of questions about whether a certain npm package should go into &lt;code&gt;dependencies&lt;/code&gt; or into &lt;code&gt;peerDependencies&lt;/code&gt;. The key to making this decision involves understanding how npm deals with version conflicts.&lt;/p&gt;

&lt;p&gt;If you have read my previous articles, you know I like you to be able to do this stuff along with me! So feel free to work along with me for this little npm experiment.&lt;/p&gt;

&lt;h3&gt;
  
  
  conflict-test Project
&lt;/h3&gt;

&lt;p&gt;To get started let’s create a trivial test project. I am going to name mine:&lt;br&gt;
&lt;code&gt;conflict-test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I created it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;md conflict-test
cd conflict-test
npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I then manually edited the &lt;strong&gt;package.json&lt;/strong&gt; file and added two dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"dependencies": {
    "todd-a": "^1.0.0",
    "todd-b": "^1.0.0"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These &lt;code&gt;todd-a&lt;/code&gt; and &lt;code&gt;todd-b&lt;/code&gt; packages also have their own dependencies:&lt;/p&gt;

&lt;h3&gt;
  
  
  todd-a
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"dependencies": {
    "lodash": "^4.17.11",
    "todd-child": "^1.0.0"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  todd-b
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"dependencies": {
    "lodash": "^4.17.11",
    "todd-child": "^2.0.0"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The thing I want you to notice here is that &lt;code&gt;todd-a&lt;/code&gt; and &lt;code&gt;todd-b&lt;/code&gt; use the same version of &lt;code&gt;lodash&lt;/code&gt;. But, they have a version conflict for &lt;code&gt;todd-child&lt;/code&gt;:&lt;br&gt;
&lt;code&gt;todd-a&lt;/code&gt; uses &lt;code&gt;todd-child&lt;/code&gt; version 1.0.0&lt;br&gt;
&lt;code&gt;todd-b&lt;/code&gt; uses &lt;code&gt;todd-child&lt;/code&gt; version 2.0.0&lt;/p&gt;

&lt;p&gt;Now I know that, like me, you are keenly interested in seeing how &lt;strong&gt;npm&lt;/strong&gt; handles this version conflict. In my main project &lt;code&gt;conflict-test&lt;/code&gt; I run &lt;code&gt;npm install&lt;/code&gt;. As we would expect, npm magically installs the &lt;code&gt;todd-a&lt;/code&gt; and &lt;code&gt;todd-b&lt;/code&gt; packages in our &lt;strong&gt;node_modules&lt;/strong&gt; folder. It also adds the packages that they depend on (the &lt;strong&gt;transitive dependencies&lt;/strong&gt;). So after running &lt;code&gt;npm install&lt;/code&gt; we take a look at the &lt;strong&gt;node_modules&lt;/strong&gt; folder. It looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_modules
├── lodash 4.17.11
├── todd-a 1.0.0
├── todd-b 1.0.0
│   └── node_modules
│       └── todd-child 2.0.0
└── todd-child 1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The interesting thing about this is that our project has one copy of &lt;code&gt;lodash&lt;/code&gt;. But, it has &lt;strong&gt;two copies&lt;/strong&gt; of &lt;code&gt;todd-child&lt;/code&gt;! Notice that &lt;code&gt;todd-b&lt;/code&gt; gets its own private copy of &lt;code&gt;todd-child 2.0.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So here is the rule:&lt;/p&gt;

&lt;blockquote&gt;npm deals with version conflicts by adding duplicate private versions of the conflicted package.&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  An Approach to Peer Dependencies
&lt;/h2&gt;

&lt;p&gt;As we saw from our experiment with npm version conflicts, if you add a package to your dependencies, there is a chance it may end up being duplicated in &lt;strong&gt;node_modules&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Sometimes, having two versions of the same package is fine. However, some packages will cause conflicts when there are two different versions of them in the same code base.&lt;/p&gt;

&lt;p&gt;For example, assume our component library was created using &lt;strong&gt;React v15&lt;/strong&gt;. We wouldn’t want our package adding another completely different version of &lt;code&gt;react&lt;/code&gt; when someone adds it as a dependency to their &lt;strong&gt;React v18&lt;/strong&gt; application.&lt;/p&gt;

&lt;p&gt;The key is:&lt;br&gt;
We don’t want our library adding another version of a package to &lt;strong&gt;node-modules&lt;/strong&gt; when that package could conflict with an existing version and cause problems.&lt;/p&gt;

&lt;h3&gt;
  
  
  peerDependencies or dependencies?
&lt;/h3&gt;

&lt;p&gt;So this brings us to the main question for our dependencies:&lt;/p&gt;

&lt;blockquote&gt;When my package depends on another package, should I put it in dependencies or peerDependencies?&lt;/blockquote&gt;

&lt;p&gt;Well, as with most technical questions: It depends.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Peer Dependencies express compatibility&lt;/strong&gt;. For example, you will want to be specific about which version of Angular or React your library is compatible with.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Guidelines
&lt;/h2&gt;

&lt;p&gt;Favor using Peer Dependencies when one of the following is true:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Having multiple copies of a package would cause conflicts&lt;/li&gt;
&lt;li&gt;The dependency is visible in your interface&lt;/li&gt;
&lt;li&gt;You want the developer to decide which version to install&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s take the example of &lt;strong&gt;angular/core&lt;/strong&gt;. Obviously, if you are creating an Angular Library, &lt;strong&gt;angular/core&lt;/strong&gt; is going to be a very visible part of your library’s interface. Hence, it belongs in your &lt;code&gt;peerDependencies&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;However, maybe your library uses &lt;code&gt;Moment.js&lt;/code&gt; internally to process some time related inputs. &lt;code&gt;Moment.js&lt;/code&gt; most likely won’t be exposed in the interface of your Angular or React components. Hence, it belongs in your &lt;code&gt;dependencies&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Angular or React as a Dependency
&lt;/h3&gt;

&lt;p&gt;Given that you are going to specify in your documentation that your library is a set of Angular or React Components, you may be asking the question:&lt;/p&gt;

&lt;blockquote&gt;Do I even need to specify angular/core as a dependency? If someone is using my library, they will already have an existing Angular project.&lt;/blockquote&gt;

&lt;p&gt;Good question!&lt;/p&gt;

&lt;p&gt;Yes, we can usually assume that for our Angular or React specific library the Workspace will already have the Angular or React packages available. Hence, technically we wouldn’t need to bother adding them to our list of dependencies.&lt;/p&gt;

&lt;p&gt;However, we really do want to tell the developer &lt;strong&gt;which Angular or React versions&lt;/strong&gt; our library is compatible with. So I recommend the following approach:&lt;/p&gt;

&lt;blockquote&gt;Add at least the &lt;code&gt;angular/core&lt;/code&gt; or &lt;code&gt;react&lt;/code&gt; package for the compatible version to your &lt;code&gt;peerDependencies&lt;/code&gt;.&lt;/blockquote&gt;

&lt;p&gt;This way developers will see a warning if they try to use your React 18 component library in their React 16 project. Don’t bother adding the other Angular or React packages. You can assume if they have &lt;code&gt;angular/core&lt;/code&gt; or &lt;code&gt;react&lt;/code&gt;, they have the other related libraries.&lt;/p&gt;

&lt;h2&gt;
  
  
  In Conclusion
&lt;/h2&gt;

&lt;p&gt;When in doubt you should probably lean toward using &lt;code&gt;peerDependencies&lt;/code&gt;. This lets the users of your package make their own choice about which packages to add.&lt;/p&gt;

</description>
      <category>npm</category>
      <category>angular</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Angular and Internet Explorer</title>
      <dc:creator>Todd Palmer</dc:creator>
      <pubDate>Fri, 14 Feb 2020 16:01:41 +0000</pubDate>
      <link>https://dev.to/tpalmer/angular-and-internet-explorer-3501</link>
      <guid>https://dev.to/tpalmer/angular-and-internet-explorer-3501</guid>
      <description>&lt;p&gt;This article addresses supporting &lt;strong&gt;Internet Explorer&lt;/strong&gt; as a browser for your &lt;strong&gt;Angular 8.x or Angular 9.x application&lt;/strong&gt;. If you are using an earlier version of Angular, please see my &lt;a href="https://medium.com/angular-in-depth/angular-and-internet-explorer-5e59bb6fb4e9"&gt;previous article on this topic&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this article we will discuss:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Getting started with an &lt;strong&gt;Angular CLI&lt;/strong&gt; application&lt;/li&gt;
&lt;li&gt;The error in &lt;strong&gt;Internet Explorer&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The steps necessary to support Internet Explorer in &lt;strong&gt;Production&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;How to support Internet Explorer in &lt;strong&gt;Development&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you just want to make it work and &lt;strong&gt;don’t care about the details&lt;/strong&gt;, you can scroll down to the section: The Cure.&lt;/p&gt;

&lt;h1&gt;
  
  
  Getting Started
&lt;/h1&gt;

&lt;p&gt;First use &lt;strong&gt;Angular CLI&lt;/strong&gt; to generate and serve a starter application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new ie-test
cd ie-test
ng serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Point basically any browser &lt;strong&gt;except Internet Explorer&lt;/strong&gt; at: &lt;code&gt;http://localhost:4200&lt;/code&gt; and you will see the basic Angular CLI application that we all know and love. In &lt;strong&gt;Firefox&lt;/strong&gt; it looks like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MYDPtV8D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/znveym82jmoggbo6svay.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MYDPtV8D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/znveym82jmoggbo6svay.png" alt="Basic Angular CLI application on FireFox"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  The Symptom
&lt;/h1&gt;

&lt;p&gt;But, if we try to use &lt;strong&gt;Internet Explorer&lt;/strong&gt;, we see something like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m3WZELHc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8z2kwqrnh7jyp142bewl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m3WZELHc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8z2kwqrnh7jyp142bewl.png" alt="The Symptom"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, it seems to be doing something because at least the title is correct. If we open the &lt;strong&gt;Browser Console&lt;/strong&gt; and re-load the page, we see something like:&lt;br&gt;
&lt;strong&gt;Unspecified error&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jCDsYV6h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8tq8k73w28nv18hjg4vz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jCDsYV6h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8tq8k73w28nv18hjg4vz.png" alt="Error in Internet Explorer Console"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  The Cure
&lt;/h1&gt;

&lt;p&gt;To get Internet Explorer working we need to do the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Un-comment some imports in the &lt;strong&gt;polyfill.ts&lt;/strong&gt; file.&lt;/li&gt;
&lt;li&gt;Install a couple of &lt;strong&gt;npm&lt;/strong&gt; packages.&lt;/li&gt;
&lt;li&gt;Modify the &lt;strong&gt;browserslist&lt;/strong&gt; file.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Below are the details for each of these steps.&lt;/p&gt;
&lt;h2&gt;
  
  
  Polyfill Imports
&lt;/h2&gt;

&lt;p&gt;First open the polyfills file in your IDE or text editor:&lt;br&gt;
&lt;code&gt;ie-test\src\polyfills.ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There are two commented out lines that you need to un-comment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// import 'classlist.js';  // Run `npm install --save classlist.js`.

// import 'web-animations-js';  // Run `npm install --save web-animations-js`.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Install npm Packages
&lt;/h2&gt;

&lt;p&gt;Notice there are some npm install commands in the comments. You need to run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save classlist.js
npm install --save web-animations-js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Modify browserslist File
&lt;/h2&gt;

&lt;p&gt;Open the browserslist file in your IDE or text editor:&lt;br&gt;
&lt;code&gt;ie-test\browserslist&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The default file created by Angular CLI looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries

# You can see what browsers were selected by your queries by running:
#   npx browserslist

&amp;gt; 0.5%
last 2 versions
Firefox ESR
not dead
not IE 9-11 # For IE 9-11 support, remove 'not'.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You need to change that last line by removing the &lt;strong&gt;not&lt;/strong&gt;. After you make the changes the last line should read:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IE 9-11 # For IE 9-11 support, remove 'not'.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Internet Explorer in Production
&lt;/h1&gt;

&lt;p&gt;For now, Internet Explorer still won’t work with &lt;code&gt;ng serve&lt;/code&gt;. There are a few more steps required.&lt;/p&gt;

&lt;p&gt;However, if all you care about is supporting Internet Explorer in production, the previous steps are enough. You can prove this to yourself by doing a production build and pointing a web server at your &lt;strong&gt;dist/ie-test&lt;/strong&gt; folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng build --prod
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Notice that now, when you run the build, it is producing the ES5 bundles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$\ie-test&amp;gt; ng build --prod
Generating ES5 bundles for differential loading...
ES5 bundle generation complete.
chunk {0} runtime-es2015.edb2fcf2778e7bf1d426.js (runtime) 1.45 kB [entry] [rendered]
chunk {0} runtime-es5.edb2fcf2778e7bf1d426.js (runtime) 1.45 kB [entry] [rendered]
chunk {2} polyfills-es2015.2987770fde9daa1d8a2e.js (polyfills) 36.4 kB [initial] [rendered]
chunk {3} polyfills-es5.ef4b1e1fc703b3ff76e3.js (polyfills-es5) 123 kB [initial] [rendered]
chunk {1} main-es2015.77c5c44e21b70d1ec41a.js (main) 169 kB [initial] [rendered]
chunk {1} main-es5.77c5c44e21b70d1ec41a.js (main) 190 kB [initial] [rendered]
chunk {4} styles.3ff695c00d717f2d2a11.css (styles) 0 bytes [initial] [rendered]
Date: 2019-12-03T23:28:06.809Z - Hash: 89a94328c69b68370cb8 - Time: 43148ms
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you can use a web server to test. For example, I will use &lt;a href="https://www.npmjs.com/package/local-web-server"&gt;local-web-server&lt;/a&gt; with npx. By the way, if you haven’t used &lt;strong&gt;npx&lt;/strong&gt;, check out &lt;a href="https://dev.to/zkat"&gt;Kat Marchán’s&lt;/a&gt; article:&lt;br&gt;
&lt;a href="https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b"&gt;Introducing npx: an npm package runner&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After building you can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd .\dist\ie-test\
npx local-web-server
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This serves up your Angular application. Point &lt;strong&gt;Internet Explorer&lt;/strong&gt; at it and you should see:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aqUlKkDO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5rjizmgz7zh5vjo3uwgv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aqUlKkDO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5rjizmgz7zh5vjo3uwgv.png" alt="Angular CLI application in Internet Explorer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt;&lt;br&gt;
If you still don’t see your application you may need to turn off &lt;strong&gt;Display intranet sites in Compatibility View&lt;/strong&gt; in your &lt;strong&gt;Compatibility View Settings&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9-Wz0-Rz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ttvgv5p8mqxtyocntzdl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9-Wz0-Rz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ttvgv5p8mqxtyocntzdl.png" alt="Internet Explorer Compatibility View"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Internet Explorer in Development
&lt;/h1&gt;

&lt;p&gt;However, if you use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;you will still get the blank Internet Explorer. This is because &lt;code&gt;ng serve&lt;/code&gt; doesn’t automatically generate the &lt;strong&gt;ES5 bundle&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;There are a couple of ways to configure this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Modify the &lt;strong&gt;tsconfig.json&lt;/strong&gt; file.&lt;/li&gt;
&lt;li&gt;Create an &lt;strong&gt;ES5&lt;/strong&gt; configuration.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Modify tsconfig.json
&lt;/h2&gt;

&lt;p&gt;You can find your &lt;strong&gt;tsconfig.json file&lt;/strong&gt; in the root of your Angular Workspace. Open it up in your IDE or text editor and you will see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"compileOnSave"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"compilerOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"baseUrl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"outDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./dist/out-tsc"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"sourceMap"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"declaration"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"downlevelIteration"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"experimentalDecorators"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"module"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"esnext"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"moduleResolution"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"importHelpers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"es2015"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"typeRoots"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"node_modules/@types"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"lib"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"es2018"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"dom"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"angularCompilerOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"fullTemplateTypeCheck"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"strictInjectionParameters"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Notice the line: &lt;code&gt;target: es2015&lt;/code&gt;. You can change it to &lt;code&gt;es5&lt;/code&gt;. It will then look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"es5"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you can run: &lt;code&gt;ng serve&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Point Internet Explorer at &lt;code&gt;http://localhost:4200&lt;/code&gt; and you should see it working just fine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating an ES5 Configuration
&lt;/h2&gt;

&lt;p&gt;If you don’t like the idea of directly modifying your tsconfig.json just so you can use Internet Explorer with ng serve, your can create an ES5 configuration.&lt;/p&gt;

&lt;p&gt;I won’t go into detail about this here as &lt;strong&gt;Ali Kamalizade&lt;/strong&gt; did a pretty good job of explaining it in his article:&lt;br&gt;
&lt;a href="https://medium.com/better-programming/how-to-fix-your-angular-app-when-its-not-working-in-ie11-eb24cb6d9920"&gt;How To Fix Your Angular App When It’s Not Working in IE11&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;Supporting &lt;strong&gt;Internet Explorer in Angular&lt;/strong&gt; is easy if you just remember where to find the &lt;strong&gt;polyfills.ts and browserslist files&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>internetexplorer</category>
    </item>
  </channel>
</rss>
