Error message: `$.each` is not a valid function in ReactJS

I am facing an issue with my ReactJS (Create-React-App) project. It renders successfully on localhost when I run the command npm start, but encounters an error when I run the build command: npm run build.

yarn run v1.16.0 $ react-scripts build Creating an optimized production build... Failed to compile.

./src/css/master.css Module build failed: TypeError: $.each is not a function

error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Surprisingly, I have not used $.each function anywhere in my master.css

master.css

@charset "utf-8";
/* CSS Document */

.
.
. (Rest of the CSS styles)

.

package.json

{
  "name": "react-express-tutorial",
  "version": "0.1.0",
  .
  . (Package dependencies and scripts)
  .
}

index.js

import React from 'react';
.
. (Importing and rendering components)
.

App.js

import React, { Component } from 'react';
.
. (Defining routes using React Router)
.

helper.jsx where jQuery is used:

import React from 'react';
import $ from 'jquery';
.
. (jQuery functions for UI manipulation)
.

It seems that there might be an issue with your jQuery usage or the way you are including it in your project. Make sure to check your imports and how jQuery is being utilized in your helper functions.

Answer №1

If you're encountering an issue, it could be due to the way Bootstrap is imported in your index.js. Consider updating it to:

import 'bootstrap/dist/css/bootstrap.min.css';

You may also want to include Bootstrap's JS like this:

import 'bootstrap/dist/js/bootstrap.min.js';

Additionally, check if you have multiple instances of jQuery being imported. Remove any duplicates and only keep the top-level import (especially those inline ´require´ imports). It's possible that Bootstrap or jQuery-UI are already pulling jQuery themselves, so including it separately may not be necessary.

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

Adjust the width of a class using CSS transitions when hovering

Is there a way to use pure CSS to adjust the widths of classes on hover? Although the transition is successfully changing the classes, class .b and .c are not impacting the width of classes that come before them. Ideally, I would like the previous class ( ...

Using Jquery to encase an element in a div while scrolling down and removing it while scrolling up

After some experimentation, I've managed to wrap an element inside a div using jQuery. My next challenge is to wrap it as you scroll down and unwrap it as you scroll up. Do you think this is achievable? Although I have succeeded in wrapping it while ...

Tips for resolving the issue of CSS blocks disappearing when designing a webpage

When creating a responsive web page, the child block "overflows" from the parent block. This causes the entire page to shift to the left and an empty bar appears on the right side, moving all the content. I need to ensure that all content is positioned cor ...

When attempting to call React.render() multiple times, an error is thrown stating: "_registerComponent(...): Target container is not a DOM element

After reading this question on Stack Overflow about whether it is acceptable to use React.render() multiple times in the DOM, I decided to test it out myself. However, when I attempted to render two components using the following code, I encountered an e ...

Which is better: Stateless functional component or additional render method in a stateful component?

Let's consider a simple scenario where we want to render a div with text outside of the render() method. Which approach would be more suitable? class StatefulComponent extends Component { ... render() { return ( {this.renderTextDiv(thi ...

Traditional alignment challenges arise when trying to position two elements in a row using HTML and CSS

Greetings to the community of stack overflow! I am facing a mundane issue with two elements (refer to code snippet below) that requires my attention. Any help or advice would be greatly appreciated. I am aiming for the final output to resemble this: With ...

When resetting the function, make sure to move the class to the closest sibling element

I am currently utilizing a slider that employs the .prev and .next jQuery functions to toggle the active class, indicating which slide is being displayed. Here is the code responsible for this functionality. It identifies the current sibling with the acti ...

Find the matching ID and consolidate all the information under one single ID

I am looking to merge objects with the same title and consolidate their data into a single object. new = [{ "data": [{ "displayName": "Peter pvt ltd", "name": "Peter Zon"}], "title&quo ...

Giving imported node modules access to React Context

Can you import a React component from node_modules in ES6, where the component depends on a Context Provider (such as react-redux 6.0), without the Provider Context being exported by that module? One possible implementation is to wrap the imported compone ...

Tips for creating responsive elements with a z-index of 1 in CSS

I have implemented the code provided in a codepen tutorial, but I replaced the world map image with a USA map. However, the dots are not responsive due to the z-index=1 specified on them. I experimented with vh, vw, and percentages, yet when I resize my s ...

Ensure that the <div> element expands and takes up all available space on the screen, without exceeding the viewable screen area

Is it possible to size a div element so that it occupies all available remaining space, but if its content exceeds the available space, the overflow is contained within without resizing or changing the height of the element? The element should have a fixed ...

Leverage JSON files for pagination in NextJS

I am currently developing a science website where the post URLs are stored in a static JSON file. ScienceTopics.json- [ { "Subject": "Mathematics", "chapters": "mathematics", "contentList": [ ...

Trouble with React Native Maps: Region not refreshing, causing map to remain stuck on a single location

My <MapView> is not updating the region properly when I scroll the map. It seems to be stuck on one region and doesn't update as expected. Even when I scroll, the same region is passed to this.props.onRegionChange, preventing the map from actual ...

Issue with the height not being updated in a parent React nested Accordion

Currently, I am in the process of developing the mobile version of my homepage. However, there seems to be a bug in my nested accordion labeled "Projects." The bug is causing an issue where the bottom projects section does not display at the correct height ...

What could be causing my media query to malfunction with MUI Components?

Seeking assistance with implementing a flex direction change in ReactJS when reaching the breakpoint of md or tablet screens. Also looking to incorporate breakpoints for desktop screens. Wondering why the media query is not functioning properly? import B ...

How to Use CSS to Crop a String from the Middle

My file has a long name and I am using CSS text-overflow: ellipsis to crop it. <style> #fileName { width: 100px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; } </style> <div id="fileName"> ...

The bytea data retrieved from Postgres does not match the original data I inserted

I have successfully integrated a React front end with a PostgreSQL back end using Express. I encountered an issue when handling byte arrays (Uint8Array) for files uploaded from the front end into the database. The file, which is 779 bytes in size, gets sto ...

Handling overlapping elements with pointer events

Suppose I have two overlapping divs, along with the following jQuery code snippet: $( "#div1" ).click(function() { console.log('click on div1'); }); $( "#div2" ).mousemove(function() { console.log('mousemove on div2'); }); From w ...

Ensure that the page header remains in place at the top of the screen as

I'm interested in maintaining the highlighted components fixed at the top of the page to avoid overlapping with the text below during scrolling. Explore more ideas here Is there a specific code I can include in my "custom-msmbstyle.css" file to achi ...

Loop through the tabs array and display varying views based on conditionals

I am currently working on building tabs and tab panels iteratively to display information, but I am facing issues in getting the desired output. For each name in a list, I need to create a tab and a corresponding tab panel underneath it. For example, the ...