Encountering an error in React Native while trying to use a custom component I created, receiving the following message: "Error: undefined Unable to resolve module <MyModule>"

I have developed a unique custom component named "react-native-weekly-calendar" with the intention of sharing it with the open source community. However, before I proceed with publishing it, I wanted to conduct some testing. Unfortunately, when attempting to test it using

npm install --save ../<component_name>
, an error is thrown.

This is the structure of my directory:

- react-native-weekly-calendar (folder)
    - index.js
    - package.json
    - src (folder)
        - Locale.js
        - Style.js

The contents of index.js:

import React, { useState, useEffect, useRef } from 'react';
import { Text, View, ScrollView, TouchableOpacity, TouchableWithoutFeedback, Modal, Platform, ActivityIndicator } from 'react-native';
import PropTypes from 'prop-types';
import moment from 'moment/min/moment-with-locales';
import DateTimePicker from '@react-native-community/datetimepicker';
import { FontAwesome } from 'react-native-vector-icons';
import { applyLocale, displayTitleByLocale } from './src/Locale';
import styles from './src/Style';

const WeeklyCalendar = props => {
    ...
}

export default WeeklyCalendar;

The contents of package.json:

{
  "name": "react-native-weekly-calendar",
  "version": "0.1.0",
  "description": "Weekly Calendar component for React Native",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  ...

To test the files above, I followed these steps:

$ npx react-native init sample
$ cd sample
$ npm install --save ../react-native-weekly-calendar
$ vim App.js

I then added

import WeeklyCalendar from 'react-native-weekly-calendar';
in App.js. Finally, I executed:

$ npx react-native run-ios

However, upon running this command in the simulator, I encountered the following error:

Unable to resolve module 'react-native-weekly-calendar' from 'App.js':react-native-weekly-calendar could not be found within the project.

I am puzzled as to why the component is not being recognized even though it is clearly located within the node_modules folder. Could it be an issue with how I configured my dependencies in package.json?

If anyone has any suggestions or insights, they would be greatly appreciated!

Answer №1

Update: Successfully upgraded my react-native version from 0.60.* to 0.61.4, using npm this time.

Initial response: I opted for

$ yarn add ../react-native-weekly-calendar

Rather than

$ npm install --save ../react-native-weekly-calendar
and it worked like a charm.

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

Storing Nodes Externally: A Guide to Dockerizing Node-Red with External Node

My current challenge involves installing numerous missing node-red nodes to a container. When I maintain the (named) container and execute it with docker start, everything functions smoothly. However, my goal is to store the installed nodes in a separate ...

Encountering a 404 error when trying to navigate to the next route using the Link component

Having issues with my login route. I've added a Link to the login route inside a button tag in my Navbar component, but when I try to access the route, I'm getting a 404 error page. --app ----pages ------component --------Navbar.js ----- ...

Tips for resolving Error: [!] CocoaPods were unable to locate compatible versions for the pod "React/Core"

Working with an M1 Chip sets me apart from my colleagues who don't have the same. My first encounter with an error was: https://i.stack.imgur.com/gRo78.png In an attempt to resolve the issue, I decided to delete the Pod, Podfile, and node_modules. I ...

Is there a way to update all scoped packages to a specific tagged version at once?

Is there a method to upgrade all scoped packages to a specific tag other than latest? For example, let's say I have multiple packages under the scope @scope, such as @scope/pkg1, @scope/pkg2, and so on. These packages have tags like stable. Is it pos ...

What is the best way to arrange child Grids within a container Grid so that they wrap to the next line while maintaining space and adjusting to the text?

Within this element, there is a main grid that contains 2 smaller grids inside. I attempted to create a fixed chat user interface by using hardcoded values and experimenting with the sm md properties. However, applying these properties caused the grid to ...

What is preventing useEffect from accessing my state variable within a return statement?

I'm struggling to figure out why my useEffect() React function is unable to access my Component's state variable. My goal is to create a log when a user abandons creating a listing in our application and navigates to another page. I've imple ...

Tips for fixing an error encountered when running a react native project for the first time

I am encountering some errors while attempting to run this project for the first time and I am unable to resolve them. Below is the content of the package.json file: { "scripts": { "start": "expo start", "andro ...

Setting up Node on a Ubuntu system

Currently, I am in the process of installing Node.js to run my Angular2 program. However, I encountered an error during the installation: npm WARN npm npm does not support Node.js v0.10.25 npm WARN npm You should probably upgrade to a newer version of nod ...

What is the best way to show an HTML response from an API call on the DOM?

After making an API call, I receive the following HTML response and I am trying to display it on the DOM as actual HTML tags, rather than just showing text with HTML tags. API response: <strong>Hello</strong> Current DOM rendering: <str ...

Caution: Be mindful when running npm install

Upon completing the npm installation process (version 4.1.2 on Windows 10) and running "npm install", a warning message popped up: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fseve ...

An in-depth guide on incorporating an Editor into a Reactjs project

Currently, I am working with Reactjs and using the Nextjs framework. My goal is to integrate the "Tinymce" editor into my project and retrieve the editor value inside a formsubmit function. How can I achieve this? Below is my current code: const editor = ...

The occurrence of the page constantly refreshing and altering the query parameters 'state' and 'session' in the URL is a common issue encountered while integrating React with keycloak

I've been experimenting with using React alongside Keycloak. I've set up the realm, users, and client successfully. However, whenever I run npm start to launch my react project, the page keeps refreshing every second and the state changes. For e ...

Mui Drawer transitions

I'm currently working on a project for a company and using Mui drawer with a variant drawer. However, I've noticed that the opening and closing of the drawer happens very quickly and I would like it to have a slower transition. The usage of the ...

React: Input field dynamically updates with each character typed

Currently, I am constructing a table using React and Material UI 5. However, I am facing an issue with the input field as it loses focus after each character is typed. Does anyone have suggestions on how to manage component re-rendering in this scenario? ...

numerous requirements for formatting utilizing Css modules

Can someone help me figure out how to set multiple conditions using a ternary operator to style an element with Css modules? I'm struggling to find the right syntax. Is it even possible? import style from './styles.module.sass' const Slider ...

The error message "npm start error - No production canister_ids.json can be located. Proceeding with local

Every time I execute npm start, the same "error" message pops up saying "No production canister_ids.json found. Continuing with local" Initially, there appeared to be a proxy issue that was visible in the browser console. I was able to resolve it by makin ...

Issue with PlayWright HTML report not being served in a Docker container

I am currently executing my PlayWright tests from a docker container to validate my ReactJS application Everything is functioning as expected, and a report directory is created successfully In the event that some tests fail, PlayWright attempts to disp ...

Implement an event listener on the reference obtained from the React context

Within the React context provider, a ref is established to be utilized by another component for setting a blur event listener. The issue arises when the blur event fails to trigger the listener. The following is a snippet of code from the context provider ...

The optimal method for handling connections to a MySQL database in NodeJS using ExpressJS

Currently, I'm in the process of building an application using ReactJS / NodeJS + ExpressJS. I've been facing some challenges with managing database connections efficiently. While the code is functional, I have observed a steady increase in the ...

Issue with SMS_MFA not being enabled due to missing delivery configuration in React and AWS Amplify

My React web application, powered by aws-amplify, interacts with AWS Cognito User Pool for user authentication. Users can choose to activate SMS MFA from the app settings. While attempting to enable SMS MFA using the aws amplify npm package, I encountere ...