Unable to locate the node module within the Rails stimulus controller

I'm facing an issue with integrating my own npm package into a Rails application that I have developed.

It's unclear whether the problem lies in the creation of the node package or within the rails app itself.

The package in question is fairly simple - you can find it here: https://www.npmjs.com/package/test-release-stuff

When attempting to import this package into my Rails project (after installing it via yarn and confirming its presence in the node modules), I encounter an error while trying to import it into my stimulus controller. The error message states:

Error: Cannot find module 'test-release'stuff'

Here is how I am importing the module:

I use the following syntax:

import foo from 'test-release-stuff'

An interesting observation is that when I tested the import in a basic React todo application, it worked seamlessly without any issues.

I suspect that the problem may lie within the webpacker configuration in my Rails app (see the config below) or there could be an error in the package.json file of the node package itself.

const { webpackConfig, merge } = require('@rails/webpacker');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const plugins = [];

if (process.env.ANALYZE === 'true') {
  plugins.push(new BundleAnalyzerPlugin());
}

const customConfig = {
  resolve: {
    extensions: ['.css'],
  },
  plugins: plugins,
};

module.exports = merge(webpackConfig, customConfig);

For the production/development/test files, my setup looks something like this:

process.env.NODE_ENV = process.env.NODE_ENV || 'production';

const webpackConfig = require('./base');

module.exports = webpackConfig;

This project is built on Rails 6.

Answer №1

It turns out that neither the rails app nor the node package was at fault.

I discovered that the issue stemmed from running the project inside a container. Even though I had previously installed an older version of the node package, updating it did not properly reflect the changes within the container. It seems that the yarn command may not have been executed at some point or there could have been caching involved.

After shutting down the containers, executing docker-compose build and docker-compose up, the changes were finally reflected and I was able to use the updated node package.

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

How can I display JSON data as key-value pairs in ReactJS?

Transitioning from JavaScript to React, I've come across some threads that touch on this topic but none quite hit the mark. I have a local JSON file that was created with a Python script, and it looks something like this: [{"hello": 10, "world": 15 ...

Using JavaScript to add a JSON string from a POST request to an already existing JSON file

I am currently working on a basic express application that receives a post request containing JSON data. My goal is to take this data and add it to an existing JSON file, if one already exists. The key value pairs in the incoming JSON may differ from those ...

The submit button seems to be unresponsive or unreactive

As a newcomer to Angular 2 and Typescript, I am in the process of building a web application. I have created several input fields and, following user submission via a button, I want to log the inputs to the console. However, it seems like my button is not ...

Patience is key when it comes to waiting for a function to finish before moving on to the next step

I'm delving into the world of node js and currently immersing myself in the concepts of promises and async/await. Here's a code snippet I've been experimenting with, but I can't quite figure out how to ensure that the code waits until t ...

Trouble with storing data in Angular Reactive Form

During my work on a project involving reactive forms, I encountered an issue with form submission. I had implemented a 'Submit' button that should submit the form upon clicking. Additionally, there was an anchor tag that, when clicked, added new ...

Peer dependency not met in NPM package

My current project is utilizing <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ad8efebe9fecabbbfa4bea4bb">[email protected]</a>. Now I am looking to integrate this package, but encountering the following error: ...

steps to address postcss security issues in react application

I recently discovered around 79 moderate vulnerabilities in the postcss package, one of which is: Moderate Regular Expression Denial of Service Package postcss ...

Trouble with the 'uppercase' package in Node.js: Receiving ERR_REQUIRE_ESM error while utilizing the require() function

I am encountering a problem with the 'upper-case' module while developing my Node.js application. My intention is to utilize the upper-case module to convert a string to uppercase, but I'm running into difficulties involving ESM and require( ...

Rails AJAX Form Issue: Devise Not Updating Data as Expected

I have implemented a Devise form on my application to update specific user information (shipping address fields) from a separate page (charges#new). The server output indicates that the update process is functioning as expected: Started PUT "/users" for : ...

What is the best way to implement this component into my vue.js project?

I am having trouble integrating this vue component into my app as it is not loading properly. You can find the source of the component here. The following warnings are showing up: Unresolved function or method isNumeric() at line 35 Unused parameter e at ...

What could be the reason for the malfunction of jQuery's show() function?

Using jQuery, I have implemented a functionality to hide a div using the hide() method. However, upon clicking a link, the div is supposed to show but unexpectedly disappears after appearing briefly. HTML Code Snippet <div id="introContent"> & ...

Node.js and Express - Dealing with Callbacks that Return Undefined Prematurely

I've hit a roadblock with this issue that's been haunting me for weeks. The first function in my code queries a MySQL database and returns a response, which is then processed by the second function. The problem lies in the fact that JavaScript ...

What is the process for setting up the Google Maps API within an Angular application without relying on any directives

Currently, I am attempting to integrate Google Maps into the application that I am developing. Utilizing the Places API for certain functionalities has been successful thus far. However, I have encountered an issue when trying to display a map on a specifi ...

iPhone height is not correct

One issue I faced was when trying to view a webpage in landscape mode on iPhones (specifically testing on model SE, but it appears that many people are experiencing the same problem with other iPhone models). I have created a simple example below, consist ...

Obtain the key's name from the select query

My task is to populate a select element from JSON data, but the challenge lies in the formatting of the JSON where the keys contain important information. I do not have control over how the data is structured. I am attempting to iterate through the JSON a ...

Leveraging the spread operator in cases where the value is null

Is there a more elegant solution for handling null values in the spread operator without using if-else statements? In this specific case, I only want to spread assignedStudents if it is not undefined. When attempting to do this without using if-else, I e ...

VueJS allows for seamless image uploading using either a gallery of images or input files

Is there a way to enable image selection from "Pick from gallery" feature in addition to the file upload functionality demonstrated in the example below? I would like the same behavior for selecting an image from the gallery as when uploading a file using ...

The ActivatedRoute.routeConfig object appears to be empty in an Angular 2 project built with Angular-cli

Two projects I've created using angular-cli are working perfectly fine. However, in one of them, the routeConfig is showing as null and I can't figure out what's causing this issue. Both projects have identical package.json files, so there ...

What is the process for installing an Ionic plugin from the GitHub repository?

The process of installing a dependency from the source code on Github instead of using the npm registry is outlined in the npm install docs. This method works smoothly for projects that are not scoped. For example, to install express, you can simply run: ...

"Sending an array in a POST request using Javascript and processing it on the server

I am trying to use ajax to send an array. Let's say the array looks like this: var anotherOne = 'anotherOneData'; var documents = ['banana', 'apple', 'monkey']; I successfully sent both a normal value and an a ...