Error: The module 'cropbox' could not be located. 2

I posed the inquiry Module not found: Error: Can't resolve 'cropbox'
Unfortunately, I did not receive a response, prompting me to delve into more specific issues and scour StackOverflow for solutions.

After investigating, I identified three key problems:

1. Rails fails to load cropbox.js

2. The cropbox.js file is unable to export the cropbox function

3. The fileUpload.js file cannot import the cropbox function

This outcome stems from one of the aforementioned issues.

Code snippet from application.html.erb:

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application' %>
<%= javascript_pack_tag 'cropbox' %>
<%= javascript_pack_tag 'fileUpload'%> #Deleted line

To address this, I intentionally refrained from compiling fileUpload which enabled Rails to successfully load clopbox.js, thereby narrowing down my focus to two problems.

If anyone can shed light on these issues, it would be greatly appreciated!

Environment:

Rails 6.0.2 Ruby 2.5.3

Snippet from app/javascript/packs/fileUpload.js:

import clopbox from './packs/cropbox' **#Here lies the issue**

uppy.on('upload-success', (file, response) => {
// retrieve uploaded file data
const uploadedFileData = response.body['data']

// set hidden field value to the uploaded file data so that it's submitted
// with the form as the attachment
hiddenInput.value = JSON.stringify(uploadedFileData)

cropbox(imagePreview, response.uploadURL, {
  onCrop(detail) {
    let fileData = JSON.parse(hiddenInput.value)
    fileData['metadata']['crop'] = detail
    hiddenInput.value = JSON.stringify(fileData)
  }
})
})

Configuration in webpacker.yml:

# Configuration details here

Sample script from app/javascript/packs/cropbox.js:

 // Code example here

Snippet from form.html.erb:

 // Form code here

Log excerpt:

Error encountered in ./app/javascript/packs/fileUpload.js
Module not found: Error: Can't resolve './packs/cropbox' in 
'/home/master/prot/prottype2/app/javascript/packs'
@ ./app/javascript/packs/fileUpload.js 1:0-38

[Webpacker] Everything's up-to-date. Nothing to do
[Webpacker] Everything's up-to-date. Nothing to do
Completed 200 OK in 39733ms (Views: 39715.1ms | ActiveRecord: 0.6ms | Allocations: 1

Answer №1

It seems that I managed to successfully load the cropbox plugin, even though I'm not entirely sure if this is the correct solution. Nonetheless, I will provide my answers here just in case.

In order to make it work, I included the following code snippet in webpacker.yml:

resolved_paths: ['app/javascript/packs']

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

Utilizing a distinct template with ui-router: A step-by-step guide

I am currently working on an Angular application that utilizes ui-router for view routing. Within my master template, I have all the layout elements set up, including my ui-view as shown below: <div class="content" ui-view> <div> Here are my ...

Do you know the steps to writing a directive on a class in Angular Js?

The restrict option is usually configured as: 'A' - for matching only attribute names 'E' - for matching only element names 'C' - for matching only class names 'M' - for matching only comments However, ' ...

Transforming ng-if state and img src dynamically in an Angular (1) directive

I've recently been exploring different ways to optimize my code, specifically by utilizing a directive instead of the standard img tags. I'm aiming to dynamically modify the ng-if state and the src based on the input value in the directive. Curr ...

RaphaelJS: Ensuring Consistent Size of SVG Path Shapes

I am currently constructing a website that features an SVG map of the United States using the user-friendly usmap jQuery plugin powered by Raphael. An event is triggered when an individual state on the map is clicked. However, when rendering a single stat ...

Error arises when using ODBC PDO alongside Ajax functionality

I've encountered a problem while working on a project at my job. I'm using PDO queries and ajax to generate dynamic elements, but I can't seem to fix a specific issue. The problem is that regardless of the option selected in two dynamically ...

Utilizing a JavaScript function to toggle the Bootstrap dropdown without the need for manual clicking

I've configured a Bootstrap dropdown in my site's mini cart that includes a lightbox effect to grey out the background content when the dropdown is activated. Here's the code snippet: $(".dropdown").on('show.bs.dropdown hide.bs.dropdow ...

The previous state is retained by useState, rather than updating to the current value

Hello, I'm currently learning about React and its functionality. My project involves having 2 select inputs that should update based on each other's value changes. However, I've noticed that after using setOptions to update the filtered va ...

Methods for invoking a function from a separate .js file within React Native Expo

I'm new to using React and I've come across a challenge: In my Main.js file, there is a button: import * as React from 'react'; import { StyleSheet, Text, View, SafeAreaView, Pressable, Alert } from 'react-native'; import { M ...

Issues arising with Intersection Observer in vue.js

Recently, I started using IntersectionObserver for the first time and I found a helpful guide at . However, I encountered an error that is causing me some trouble. [Vue warn]: Error in mounted hook: "TypeError: Failed to construct 'IntersectionObserv ...

Is the AJAX function failing to execute? Potential issue with the database connection?

I am currently working on setting up my project on the localhost. I've encountered an issue with the built-in ajax function upon success. Below is the snippet of the javascript function in question: function fetchResults(page, searchString) { page ...

What is the best way to showcase a QR code on a mesh using three.js?

I utilized the QRcode library available at to try and showcase it on a mesh object as a texture using the following code: var qrcode = new QRCode( "test", { text: "http://jindo.dev.naver.com/collie", width: 128, height: 128, colorDark : " ...

The function 'send' cannot be called as it is undefined (response is undefined) within Express.js

I have encountered a challenge while trying to pass a variable from my index.html to the database (maildata.js) through app.js (server) and retrieve the corresponding data. I have successfully retrieved the data from the database, but I am facing difficult ...

Employ Mustache.js for displaying a series of data points retrieved from a JSON reply

Utilizing Mustache.js to format the response from a jQuery getJSON() request has been quite helpful. The getJSON request is responsible for obtaining a list of image names, which I plan to display at the end of my content once the call is made. The JSON d ...

Creating a custom function in a Node.js application and rendering its output in the front-end interface

I've been trying to scrape data from a website and display it using innerHTML, but I'm running into some issues. The code snippet I'm using is: document.getElementById('results').innerHTML = searchJobs(''); However, I ke ...

Generate dynamic DIV elements and populate them with content

Can you assist me in getting this code to function properly? My goal is to dynamically create elements inside a div and fill each element with a value fetched from the database through a server-side function. I'm unsure if there's a better approa ...

Struggling with running my React App as I'm encountering some errors

Check out the code on Github: https://github.com/bhatvikrant/IndecisionApp I have already run npm i and then executed yarn run dev-server, utilizing webpack. My operating system is MacOs. I have also created the .babelrc file. The issue I encountered aft ...

Recreated using CSS and JavaScript: iOS "Background Open" Animation

I am currently seeking a method to replicate the iOS Safari animation that occurs when opening a link in the background (the item jumps up and quickly animates to where it can be accessed) - This same animation is also seen on OSX Safari's "save to re ...

Inject the JavaScript template into an HTML page within a <div> element

Looking for a solution to format JSON API data listing books with title, author, and other properties into HTML? Utilizing ES6 backticks and JavaScript templating, the challenge arises when needing to display two cards per row on the HTML page. The issue l ...

After running the map.fitBounds function, you can retrieve the current boundary coordinates using map.getBounds() in

After calling fitBounds() to recenter and zoom the map to fit the bounds, I expected getBounds() to return a valid bound. However, it is returning nil. Below is the code snippet that reproduces this issue: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...

What sets apart the usage of :host from its absence?

I'm finding it quite confusing to understand the usage of :host in Angular. For instance, let's consider a CSS file named a-component.component.css and its corresponding HTML file named a-component.component.html with a selector of app-a-compone ...