Ways to avoid slash expansion in custom arguments for NPM?

For my application's build process, I have the following setup:

"scripts": {
    ...
    "build": "ng build --prod",
    ...

In order to set the base href for my project, I include this in my Bash script:

npm run build -- --base-href "/mydir/"

However, when executing the Bash script, the base href is set incorrectly to:

ng build --prod "--base-href" "C:/Program Files/Git/mydir/"

What I actually want is for the base href to be set as:

ng build --prod "--base-href" "/mydir/"

Answer №1

Consider following the advice given by Tolga Balci (tolgabalci) on angular/angular-cli issue 5606:

Check out "MinGW Posix path conversion" to understand when conversions take place:

To prevent git bash from converting the -bh parameter, set the MSYS2_ARG_CONV_EXCL environment variable before running ng like this:

MSYS2_ARG_CONV_EXCL="-bh=" ng build --prod -bh="/en/"

Note that you must use an equals sign (=) with -bh, not a space, for the exclusion to work correctly. Otherwise, MSYS2_ARG_CONV_EXCL will interpret the value after the space as a separate parameter.

The original poster, Marco Eckstein, confirms this solution in the discussion comments:

In my case, it looks like this (all on the same line):

MSYS2_ARG_CONV_EXCL="--base-href" npm run build -- --base-href="/mydir/" 

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

The bamboo construction falters as webpack is unable to locate the node_modules

After setting up my Angular project with webpack in version 1.7, everything runs smoothly locally when I execute the npm run build task to launch webpack. However, I encountered an issue when trying to set up a plan for continuous integration using bamboo ...

Error message in jQuery UI: "base cannot be used as a constructor"

After installing jQuery and jQuery UI using npm, I tried to use require('jquery-ui/ui/widgets/selectable') in one of my own JavaScript modules. However, it resulted in the error message below: TypeError: base is not a constructor (widget.js:108) ...

Firebase encountered a FetchError due to an invalid response body when attempting to fetch data from https://serviceusage.googleapis.com/v1/projects/. The issue was caused by incorrect

While developing a Firebase project locally, everything was running smoothly in emulators. However, after updating Firebase-tools to version 12.4.3, I ran into this error message during deployment: Error: FetchError: Invalid response body while trying to ...

I'm having trouble launching the Vue UI after successfully installing the Vue CLI - any ideas why?

After installing the following versions: node 8.11.2 npm 6.3.0 I proceeded to install the Vue CLI (@vue/[email protected]): npm i -g @vue/cli However, upon running the command below: vue ui An error message was displayed as follows: Error: Cann ...

Encountering a hiccup when working with Angular and npm

Error: The '@angular-devkit/build-angular:browser' builder's node package could not be located. Upon running npm start, the console displays this error message: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="473 ...

Testing Angular Library Before Release

My Angular library consists of modules, each containing services. I am looking for a way to easily test my library when I make changes to one of the services. Is there a simple solution that doesn't involve publishing and installing it in the main pr ...

The Angular 2 project, built with the CLI tool, has been transformed into an npm

We have a project in the works that involves creating a large application using angular 2. This project consists of one main parent angular 2 application and three separate sub-child applications that are unrelated to each other. Each of these sub-child ...

Angular 2 release candidate 3 encounters issues with unfulfilled dependencies

Having encountered an issue with npm, specifically related to dependencies while using packages.json from the official Angular2 site's quick start guide. Yesterday everything was functioning correctly, but today I am facing difficulties as npm is unab ...

Problem with NPM caching

Using Jenkins to execute test cases based on Cypress, I followed the kitchen sink example provided by Cypress on their GitHub repository here. However, when running this in a Jenkins job, an error occurred. The error message displayed: NPM WARN prepare re ...

Try running ng build watch and gulp watch simultaneously on one console

Is it possible to simultaneously run ng build --watch and gulp watch:ng in the same console? Below is the task code: gulp.task('watch:ng', function () { gulp.watch('ng/dist/ng/*', gulp.series('copy-ng')); }); I am looking ...

Blank screen on ndb window

I've been diligently searching for a solution to this problem, but unfortunately, both myself and my team are unable to find one. Following the simple instructions to install ndb globally on a Mac Mojave setup - using npm install -g ndb - was smooth ...

Encountering an error while attempting to install expo-cli globally using npm install

I'm experiencing difficulties with the installation of expo-cli. How can I resolve this error? You can refer to the image provided below for assistance. UPDATE: I have included the error logs from my notepad Raw JSON explanation object: For a detailed ...

Vue-ctl project creation halted by operating system rejection

While working on a Vue-CLI project, I encountered an issue. Has anyone else faced this problem before? Operating system: Windows 10 - Command Prompt (admin rights) @vue-cli version: 4.5.4 npm version: 6.14.6 Here is the command I ran: vue create font_ ...

Typedoc Error: Attempted to assign a value to an undefined option (mode)

After installing typedoc with the command npm install typedoc --save-dev, I proceeded to add typedocOptions to tsconfig.json: { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", // ...some lin ...

What is the method for executing the command "npm test" through the WebStorm file watcher feature?

How can I set up npm test to automatically run whenever a file changes in Webstorm? I'm aware of creating a run configuration from NPM but prefer not having to trigger it manually each time. ...

Steps for building a react-admin app using the tutorial

Currently, I am using Ubuntu and attempting to develop a react-admin application. The command I executed was "yarn create react-admin test-admin", selecting JSON Server as the data provider and None as the authentication provider. I did not add any resour ...

Tips on declaring the node_modules directory for a node module that is referenced locally

In order to avoid duplication of node modules in the final build, we need to specify the node_modules folder for locally referenced node modules that are located in an external folder relative to the current application folder. We have encountered a situa ...

Error: Unable to simplify version range

Attempting to follow the Express beginner's guide. I created an app and executed npm install as per the provided instructions. > npx express-generator --view=pug myapp > npm install npm ERR! semver.simplifyRange is not a function npm ERR! A com ...

Trouble loading CSS file in Vue library from npm package

When using vue-cli to build a library (npm package) that functions for both SSR and client-side, everything seems to be functioning correctly except for one issue; the CSS only loads if the component is present on the page being refreshed. However, when ac ...

Struggling to resolve my issue using npm install

Encountering an issue with npm. The error message I received is below. More details can be provided upon request as I am not sure what the problem is. I tried searching for a solution online but could not find any similar errors. Is there a documentation a ...