Issues arising with the proper functioning of the normalModuleReplacmentPlugin in Webpack on Windows

Recently, I began developing a library in TypeScript to fetch data from an API and using Webpack as a bundler. The library needs to interact with different APIs for development, testing, and production environments, so I created various environment files that should be replaced by Webpack.

While I'm on Ubuntu 18.04, one of our developers working on the library is using Windows and noticed that the file replacement wasn't functioning correctly on his local machine.

Below is an excerpt from my GitHub repository's webpack.config.js:

const merge = require('webpack-merge');
const path = require('path');

// Common configuration object...
...

// Environment configurations...
...

module.exports = mode => {
    // Logic for merging common and environment-specific configs...
};

And here is an example of the prod config file:

const CleanWebpackPlugin = require('clean-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const webpack = require('webpack');

// Production configuration with NormalModuleReplacementPlugin...
...

module.exports = {
    // Prod config details...
};

I suspect that the issue does not lie with Webpack but rather how it's being used.

GitHub repo: https://github.com/ManticSic/normalModuleReplacmentPlugin-issue-windows
Run npm ci followed by npm run build (or npm run build-dev for dev env).
Look for the important details towards the end of line #1.

Expected output:

...,t.environment={bar:"Prod"}...

Actual output on Windows:
...,t.environment={bar:"Normal"}...

Answer №1

As anticipated, the issue was caused by the user sitting at the computer...
Incorrect file system separators were employed.

Substituting \/ with [\\\/] resolves the issue!
Complete regex:

/src[\\\/]environments[\\\/]environment.ts/

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

NextJS: Route Handler encountering Method Not Allowed (405) error when trying to redirect

Current NextJs version is 13.4.3 I have set up a route handler to capture POST requests. For more information on route handlers, please refer to the documentation at [https://nextjs.org/docs/app/building-your-application/routing/router-handlers] In this ...

I encountered an error while using react-create-app: "./src/index.css (./node_modules/react-scripts/node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1"

Recently, I started a project with create-react-app and everything was smooth sailing until this morning. Even the font wasn't causing any issues. Upon running npm start, I encountered the following error message: ./src/index.css (./node_modules/react ...

What sets npm init apart from npm init --yes?

I need some clarification on the distinction between npm init and npm init --yes in node.js as I am still a beginner with the platform. Your assistance in resolving this confusion would be greatly appreciated. Thank you. ...

"Utilizing an exported constant from a TypeScript file in a JavaScript file: A step-by-step guide

I am facing an issue when trying to import a constant from a TypeScript file into a JavaScript file. I keep encountering the error Unexpected token, expected ,. This is how the constant looks in the ts file: export const articleQuery = (slug: string, cate ...

Can TypeScript restrict a callback parameter based on the type of another parameter using generics?

I am currently developing an event manager system. The main objective is to allow users to subscribe to events by providing an event type and a callback function. In my implementation, events are represented as classes, where AwesomeEventType in the exampl ...

Generate a versatile Union type featuring a mapped property

I am currently working with different types of data enum DataTypes { Email = 'email', Checkbox = 'checkbox', } type DataTypeValues = { [DataTypes.Email]: string; [DataTypes.Checkbox]: boolean; }; type Type1<T extends DataTy ...

What is the recommended approach for sending a null value to a mandatory property in a Vue.js component?

Setup: Vue.js (3.2) with Composition API, TypeScript, and Visual Studio Code File type.ts: export class GeographicCoordinate { latitude: number; longitude: number; altitude?: number; constructor(latitude: number, longitude: number, altitude?: num ...

Having trouble removing unnecessary packages from your node_modules directory? Unfortunately, the npm rm command seems to be ineffective in this

Removing packages from node_modules has proven to be quite a challenge for me. Despite following a tutorial's instructions to use npm rm <pkg>, I find that dependencies still persist. Even after deleting the package from my package.json, it rem ...

Watch a video on the client by streaming it from an external server via my node.js server

I have videos stored on a server named server1 that are inaccessible to some clients. However, there is another server, server2, that has access to server1 and the clients are able to access it as well. I am looking for a solution that will allow the clie ...

What is the process for incorporating a personalized inputComponent JSX <input /> into a react-phone-number-input PhoneInput component?

Instructions to follow when working with code. react-phone-number-input provides the option for users to replace its default <input /> JSX tag with a custom one, requiring the type React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTML ...

Having trouble accessing an injector service within the promise of a dynamically loaded JavaScript function that has been assigned to a global variable

Query I am facing an issue while trying to integrate PayPal with Angular. I am encountering difficulties when attempting to call an injected service inside a function of the promise returned. Any assistance in resolving this would be greatly appreciated. ...

Steps for setting up the 'node_modules' folder in an older Angular project using the 'npm install' command

Currently, I am in the process of transferring our project code from our repository to a new laptop. The project was initially developed on Angular 5 last year. However, the new laptop is equipped with the latest versions of Angular CLI, NodeJS, and NPM to ...

Troubleshooting Cloudflare Pages Deployment: Encountering 401 Unauthorized error while trying to install fontawesome dependency using Y

Everything was running smoothly with my deployments until I decided to add FontAwesome into the mix. Surprisingly, it functions perfectly fine on my local environment even with FontAwesome included. However, once I introduce the FontAwesome dependency and ...

Angular: Understanding Render Delay Caused by *ngIf and Expression Changes from Filters

ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: false'. Current value: 'ngIf: true'. Encountering the above error in the console. In my code, I have filters that control ...

Running the `npm start` command in Angular tends to be quite time-consuming

When I use Visual Studio Code to run Angular projects, my laptop seems to take a longer time when running the server through npm start compared to others. Could this delay be related to my PC specifications, or is there something I can do to improve it? ...

How to create a collapse feature that allows only one item to be open at a time in Angular

I developed an angular app with a collapse feature, but I noticed that multiple collapses can be open at once. I am utilizing Ng-Bootstrap collapse for this functionality. Below is the code snippet from the TS file: public isCollapsed = true; And here is ...

Problem with Ionic 2 checkboxes in segment controls

I encountered an issue with my screen layout. https://i.sstatic.net/bFeZN.png The problem arises when I select checkboxes from the first segment (Man Segment) and move to the second segment (Woman Segment) to choose other checkboxes. Upon returning to th ...

Leveraging TypeScript's enum with function overloading

I am encountering an issue while trying to implement function overloading in TypeScript with an enum as a parameter and a second argument that depends on the enum's type. Here is the breakdown: If the enum is FOO, the second argument should be of t ...

Developing Angular2 applications in Visual Studio Team Services (formerly known as Visual Studio Online)

Currently, I have an angular2 client integrated into a Visual Studio vNext (ASP.Net 5) project. During my attempt to create a build in Visual Studio Team Services, I encountered errors similar to this one during the build step: It appears that module &a ...

Filtering arrays of objects dynamically using Typescript

I am looking to create a dynamic filter for an array of objects where I can search every key's value without specifying the key itself. The goal is to return the matched objects, similar to how the angular material table filters all columns. [ { ...