Do not include .js files in React.js build process

Is there a way to prevent a specific .js file from being included in the

npm run build

I attempted to exclude it by adding:

"build": "react-scripts build && rm -rf build/config-local.js",

to package.json, but I received the following error:

rm is not recognized as a function

Does anyone know how to resolve this issue?

Appreciate your help.

Answer №1

If you want to exclude a .js file that is included in your project through the react-scripts build command, you will need to modify the source code of react-scripts. Alternatively, deleting the file afterwards may be the easiest solution.

Explanation:

But why isn't this working?

rm is not recognized as a function

  • The rm command is used for deleting files/folders in bash.
  • In Windows, the equivalent is using DEL in cmd.exe.

It seems like you are encountering this error because you are running it on a Windows system.

Solution:

To have a cross-platform way of deleting files/folders, you can make use of rimraf.

  1. Firstly, navigate to your project directory and install rimraf by executing the following command:

    npm install rimraf --save-dev
    
  2. Next, update the build script in your package.json file as follows:

    "build": "react-scripts build && rimraf build/config-local.js",
    

    Note: The original rm -rf has been replaced with rimraf

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

What is the best way to stop event bubbling in react-router-dom when using the <Link> component?

Hey there! I have a situation that I need help with. I tried putting the Link around the whole post so that I could prevent bubbling for individual buttons, but for some reason stopPropagation() is not working as intended. Following advice from another s ...

Unable to eliminate hover underline on link

Struggling to remove the underline from all links globally in my NextJS project has been quite a challenge. I've attempted various methods, including CSS (by importing the globals.css file into _app.tsx) and through ChakraUI. The only solution that ...

I'm curious why my setState function seems to be returning an array instead of updating the state directly in my React component. And then

In the following code snippet, an attempt is made to verify whether a URL is accessible or not. The URLs to be verified are stored in a state called trackedUrls. The state is updated using an asynchronous function named checkAll. Before the update, the o ...

What type of event does the Input element in material-ui v1 listen for?

I'm currently grappling with material-ui v1 as I search for the appropriate event type for input elements. Take a look at the code snippet below: <Select value={this.numberOfTickets} onChange={this.setNumberOfTickets}> .... Here is the impleme ...

Tips for validating an email address using ReactJS

I'm currently working on customizing the email verification process for a signup form in ReactJS. My goal is to replace the default email verification with my own validation criteria. Initially, I want to ensure that the entered email address contains ...

When a user clicks on a specific accordion, the icon for all accordions under mui control will change

My current task involves mapping over an array of data to render multiple controlled accordions. Each accordion should open/close individually upon clicking, but I'm facing an issue where the icons for all accordions are changing when I interact with ...

Use ReactJS and Material UI to select the checkboxes for items that are a match

I need help figuring out how to display checkboxes for an array and then mark the checkboxes for items that match a user array. Here is the user's array: [ { "Category": "XXX", "Name": "123" ...

Using the .get() method to retrieve Firebase documents results in an error message saying "'is not a function'"

I'm currently attempting to retrieve all the documents from a specific collection in Firebase using the following code snippet: const userCollectionRef = collection(db, currentUser?.uid) const snapshot = await userCollectionRef.get() for (const doc of ...

Customize Material-Table: Adjusting Detail Panel Icon Rotation upon Row Expansion

I've made a modification to the layout of the detail panel icon (mui ChevronLeft) so that it now appears on the right side of the table by using the options={{detailPanelColumnAlignment: "right"}} property. TableIcons : DetailPanel: for ...

Is it possible to implement CSS code from a server request into a React application?

With a single React app that hosts numerous customer websites which can be customized in various ways, I want to enable users to apply their own CSS code to their respective sites. Since users typically don't switch directly between websites, applying ...

Can someone please guide me on how to transfer information from a material ui datagrid Row to a form input?

I need assistance. I have a table that holds user data and I want to create a functionality where clicking on the edit button opens a dialogue box with a form pre-filled with the user's initial data. However, I'm currently only able to pass the u ...

Developing the headers for a service using React.js

As someone new to ReactJs, I'm curious about the various methods we can use to include Headers in our service Url before making a call. While I'm familiar with how GET/POST Calls are made in angular Js after including headers, I'd like to l ...

What is the best way to save an array of objects from an Axios response into a React State using TypeScript?

Apologies in advance, as I am working on a professional project and cannot provide specific details. Therefore, I need to describe the situation without revealing actual terms. I am making a GET request to an API that responds in the following format: [0: ...

Using Next.js to Retrieve JSON Data and Render it in Components

I want to refactor the MainMenu function and getStaticProps from index.js into separate components. Here is my current index.js page that is functioning correctly. #index.js import Link from 'next/link'; function MainMenu({ menuLists }) { re ...

The self-registration of the module was unsuccessful. A custom build C++ node module compiled with cmake-js was utilized within the Electron app

Currently working on a project where I created a C++ module for Node and compiled it with CMake. However, when I tried to use this module in my main Electron app, it resulted in errors. To demonstrate the issue, I have created a minimal repository here: h ...

When attempting to create, an error occurs: Uncaught TypeError: Unable to access properties of undefined (retrieving 'id')

In the process of creating a public prayer journal that allows users to include their favorite Bible verses, I encountered an issue while trying to add a prayer or verse. The error message "caught (in promise) TypeError: Cannot read properties of undefined ...

I'm curious why one of my Material UI autocomplete components is displaying options with a blue background while the other isn't. Take a look at the code sandbox for more insight

UPDATE: Problem solved! I managed to find a solution and have updated my sandbox with the fix! REVISION: After some investigation, I have identified that the issue lies within this specific line of code in the autocomplete... isOptionEqualToValue={(option ...

What is the best way to present JSON data retrieved from an API on different pages using Next.js?

I am currently working on two pages that are connected: one is an API page called secured.js (where user session data is processed) and the other is a normal page also named secured.js (which displays the processed content from the API page). This is the ...

Issue with Material UI scrollable tabs failing to render properly in Internet Explorer

Currently, we are integrating Material UI into our tab control for our React Web UI. Everything is functioning smoothly in Chrome, but when we attempted to test it in IE, the page failed to load and presented the error below: Unhandled promise rejection ...

Are there any npm packages pre-installed in Azure functions? If there are, how can I verify their presence?

As I work on building my Azure function locally using WebStorm/PHPStorm, I am curious about if there are any pre-installed npm packages readily available in the cloud for Azure functions. It can be quite cumbersome to include all necessary packages each ...