Tips for choosing the node_modules distribution flavor to include in your webpack bundle

Issue:

Following the update of AJV.js to Version 6.4, my vendor bundle now includes the "uri-js" ESNEXT version instead of the ES5 version, causing compatibility issues with IE11.

Analysis:

Upon investigation, I discovered that AJV references uri-js using a require('uri-js') call and that uri-js comes in two variants:

/node_modules/uri-js/dist/:

  • es5
  • esnext

Webpack (Version 4.8) bundles the 'esnext' variant of uri-js into the vendor-bundle rather than the 'es5' variant for unknown reasons. I was unable to locate where or how I can specify my preferred build target.

This is my webpack.config.js file:

(contents of webpack.config.js)

package.json:

(contents of package.json)

While I comprehend that my own code gets transpiled to ES5 using the TypeScript (Version 2.8) compiler, the handling of node_modules, specifically those already containing an ES5 version within their dist folder, remains unclear.

In case it influences the situation, here is my tsconfig.json file:

(contents of tsconfig.json)

I also considered implementing Babel to downgrade all node_modules to ES5, but this approach seems excessive given that the modules already include ES5 versions.

Inquiries:

  1. Is there a way to specify that I prefer the ES5 version of the dist folder for my node_modules? Perhaps in my webpack.config or in package.json?

  2. How does the selection process for the appropriate node_modules/.../dist/ folders work?

Answer №1

  1. Is there a way to specify that I prefer the ES5 version of the dist folder for my node_modules? Can this be done in webpack.config or package.json?

It seems that there is no universal method for handling different versions (such as ES5, ESNEXT, etc.) of the same NPM package. Each package has its own unique approach. Therefore, custom configurations need to be implemented into task-runners like Gulp, Webpack, Grunt, etc., to address specific requirements.

  1. How exactly does the selection process work for the right node_modules/.../dist/ folders?

A typical NPM package includes a package.json file with a main field that determines what should be included or used within your application, as well as what the bundler picks up. In the absence of a defined main value, the default choice tends to be index.js.

The specifics of the selection process vary from package to package and extend to the folder structure within the package. Some packages utilize different folders such as /dist/.. for various versions, while others segregate debug and production releases. Ultimately, it depends on the individual package which files or versions are utilized.

Unlike the structured system found in .net Nuget packages, there is no standardized format similar to the lib/... folder here.

One point of confusion remains regarding why the ESNEXT version of URL-JS takes precedence over its ES5 counterpart when the URL-JS link specifically points to the latter. This is an ongoing investigation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to extract various pieces of data from a single object and implement them in a NextJs 13 application directory?

My Django RESTapi is providing output data in the following format: { "count": 1000, "next": "http://127.0.0.1:8000/store/products/?page=2", "previous": null, "results": [ { "id": 648, ...

Incorporating an external JavaScript file into Vue.js

Is there a way to include and initialize a JavaScript file named mymain.min.js in the assets folder of my project using VueJS with webpack? Update in Webpack.base.conf resolve: { extensions: ['.js', '.vue', '.json'], ...

Engaging with JSON data inputs

Need help! I'm attempting to fetch JSON data using AJAX and load it into a select control. However, the process seems to get stuck at "Downloading the recipes....". Any insights on what might be causing this issue? (Tried a few fixes but nothing has w ...

Utilizing TypeScript with Sequelize for the Repository Design Pattern

I am in the process of converting my Express API Template to TypeScript, and I am encountering difficulties with the repositories. In JavaScript, the approach would be like this: export default class BaseRepository { async all() { return th ...

Using Angular 2 to execute an interface while making an HTTP GET request

I've managed to successfully retrieve and display data from a JSON object using *ngFor in Angular. However, I am struggling with applying an interface to the retrieved data. This is the content of my interface file: import {Offer} from './offer ...

Error Encountered: POST method not supported in ajax request using djangoIs this a

I am currently encountering an issue while trying to pass form data values through ajax. I keep getting a method not allowed error when attempting to add a comment on a blog post. The form below is located inside the blog_detail page: <form id="co ...

Do not directly change a prop's value as it will be replaced when the parent component re-renders. Use v-form instead

I'm currently in the process of developing an app using nuxt along with vuetify 2.x, and I keep encountering a specific error message: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Inste ...

Alter the color of a single character using JQuery, all while keeping the HTML tags unchanged

I'm currently working on iterating through the DOM using JQuery in order to change the color of every occurrence of the letter m. Here is what I have so far: $(document).ready(function(){ var m = "<span style='color: red;'>m</span& ...

generate a collection using a string of variables

I'm looking for a way to pass a string as the name of an array to a function, and have that function create the array. For example: createArray('array_name', data); function createArray(array_name, data){ var new_array = []; // pe ...

What is causing the ng-show function to malfunction after building with phonegap?

My current javascript framework for my PhoneGap app is the Ionic Framework. I have a specific item on one of my pages that I want to make expandable and collapsible by clicking an anchor on the page. Here is what the code looks like: In the HTML file: & ...

Employing selenium.isElementPresent in Selenium 1 does not have the capability to identify an element that is dynamically added to the Document Object Model (

After trying out various locators, I have yet to find one that can detect an element that was added to the DOM. Below is my latest attempt at solving this issue: selenium.fireEvent("//button[2]", "click"); waitUntil(new Condition() { @Override pu ...

JavaScript and jQuery experiencing difficulty rendering proper style and image in output display

I am currently working on code that extracts information from a JSON variable and displays it on a map. The code looks like this: marker.info_window_content = place.image + '<br/>' +"<h4>" + place.name + "</h4> ...

Steps to invoke a function in a PHP file from an external JavaScript file

Can anyone assist me with calling the function below in my PHP file? function update_hidden_input(saved_tokens, hidden_input) { var token_values = $.map(saved_tokens, function (el) { //alert(el[settings.tokenValue]); return el[ ...

Uncovering the Full Scope of a LinkedIn Profile with Typescript

Hello, I am currently in the process of developing an Ionic2 framework app that includes social login functionality. Up to this point, I have successfully integrated Google Plus and Facebook buttons. Now, I would like to add LinkedIn login as well. The c ...

Incorporating properties of the parent class through Mixin techniques

I'm encountering an issue while trying to access a property from an inherited class within a mixin class BaseItem{ public id:string; constructor(id:string) { this.id =id; } } abstract class ConfigMixin<K extends BaseItem& ...

The error message "node Unable to iterate over property 'forEach' because it is undefined" appeared

I am facing an error and unable to find the solution. I believe my code is correct. It is related to a video lesson where I attempt to display popular photos from Instagram using the Instagram API. However, when I try to execute it, I encounter this issue. ...

Changing an object into an array for saving and transforming it back to an array for usage in JavaScript

I am dealing with a unique situation where I have an object created from dynamic checkboxes in Angular. The structure of the object looks like this: {"United States":true,"Canada":true,"Australia":false} While this format works well for storing values, I ...

What is causing Puppeteer to not wait?

It's my understanding that in the code await Promise.all(...), the sequence of events should be: First console.log is printed 9-second delay occurs Last console.log is printed How can I adjust the timing of the 3rd print statement to be displayed af ...

When attempting to deploy a Teams Toolkit app through CI/CD, the process fails with the error message stating, "This command is only compatible with projects created using Teams Toolkit."

My chatbot in the MS Teams app provisions, deploys, and runs smoothly locally, in testtool, and on Azure. Now, I've decided to take it a step further by setting up CI/CD for this project. Setting up CI/CD for Node.js project is new to me, but I' ...

Utilizing window.matchMedia in Javascript to retain user selections during page transitions

I am encountering difficulties with the prefers-color-scheme feature and the logic I am attempting to implement. Specifically, I have a toggle on my website that allows users to override their preferred color scheme (black or light mode). However, I am fac ...