Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: __require.context is not a function #73

Closed
noelrappin opened this issue Sep 6, 2021 · 4 comments
Closed

Uncaught TypeError: __require.context is not a function #73

noelrappin opened this issue Sep 6, 2021 · 4 comments

Comments

@noelrappin
Copy link

I get this trying to install Stimulus using the new esbuild-rails (which I guess has just been replaced by jsbundling-rails, but I think the issue holds

Uncaught TypeError: __require.context is not a function, it's from the controllers/index.js line

const context = require.context("controllers", true, /_controller\.(js|ts)$/)

I'm not sure whether this is a case where the install is giving me the wrong thing (and I should be using the node install and importing all my files one-by-one) or whether there's a way to make the require work.

Thanks

@dhh
Copy link
Member

dhh commented Sep 6, 2021

The latest stimulus-rails uses a different approach to loading the controllers. Right now it's "manual", but I'm working on something better. esbuild doesn't have context, though, so the old Webpack approach won't work.

@dhh
Copy link
Member

dhh commented Sep 6, 2021

Basically, you can't do file-based globs at all with esbuild. (Without a plugin, and I'm keen to avoid that).

@dhh dhh closed this as completed Sep 6, 2021
@noelrappin
Copy link
Author

Are we eventually going to get to something like #32?

@dhh
Copy link
Member

dhh commented Sep 6, 2021

Auto loading only works with import maps, and there I’m not sure it’s worth the effort. But with import maps we at least have a straight forward way to glob.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants