Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
Webpack 5 Isn't Loading StimulusJS Controllers Via require.context()

I am migrating a Rails project from Webpacker to Webpack 5. The last hiccup is that Webpack isn't properly importing my Stimulus controllers. Per the Stimulus docs, I have this code in my entrypoint:

// app/javascript/global.js

import { Application } from "@hotwired/stimulus"
import { definitionsFromContext } from "@hotwired/stimulus-webpack-helpers"

window.Stimulus = Application.start()
const context = require.context("./src/controllers", true, /\.js$/)
Stimulus.load(definitionsFromContext(context))

The controllers themselves live in app/javascript/src/controllers.

The assets compile as expected, but the Stimulus controllers aren't registered. Moreover, when I log the output from require.context() above, I get the following console error:

function t(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}

I know the file path to my controllers is correct, because when I change it to something obviously incorrect, the build fails. In addition, when I manually register a controller:

import { Application } from "@hotwired/stimulus"
import Tabs from "./tabs_controller";
const application = Application.start()
application.register("tabs", Tabs);

The controller loads and functions as expected, so I don't believe it's a Stimulus issue, specifically.

Am I configuring the require.context() method incorrectly? It's all boilerplate straight from the documentation, so it should work, but I'm at a loss for what else to troubleshoot.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda