-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Actioncable Webpacker compilation issues with Rails 6 in production #35501
Comments
I think I ran in to the same issue. I have a new rails 6.0.0.beta3 project, and when I deployed it to my staging environment, I got the same error. I was able to resolve it by copying I'm not sure why it works and it's obviously not a good solution, but hopefully it will provide a clue to somebody who understands this better than me! I am using TypeScript if that makes a difference. |
Also seeing this problem with rails 6.0.0.rc1. @nextchessmove workaround worked for me too. |
I followed @nextchessmove's workaround to fix my issue, but had to do a bit more alteration. I run the same code through Storybook in React components and the following line would fail when Storybook tried to run it through Webpack.
the error was:
Maybe the UMD build of the I fixed my issue by doing a |
Seeing this problem with Rails 6.0.0.rc1 too, on a fresh Rails depot app (from the Agile Web Development with Rails book) - deployed to Heroku. Locally everything with ActionCable works fine. With Rails 6 RC1 my package.json looks like this;
|
Try updating your |
No luck, same error - my
|
tired to fix and just added to
|
I am having the same issue after updating to rails 6 and bumping the npm package to |
I'm facing this same issue when deploying in production, and am looking for a fix. |
What solved it for me is removing this from the bottom of babel.config.js
|
@MelfQuin that fixed it for me, thanks mate. |
@jessehanley @MelfQuin this also worked for me, Thanks guys. |
@MelfQuin also worked for me too, thank you guys, dont know why not so many people mention about this error. |
I'm also having this same issue in test environment. We are precompiling in CI before running tests, and while that completes successfully, any test hitting JS assets dies with the same "r is not a function" error. Updating Edit: Excluding |
@xaviablaza https://github.com/rails/webpacker/blob/master/docs/v4-upgrade.md#excluding-node_modules-from-being-transpiled-by-babel-loader this worked for me. just add |
@MelfQuin Worked for me as well, though I am not sure if it has any side effects? This babel plugin was there for a reason i suppose. So we still await some official solution, if we can pin point issue i would be happy to put up a PR, or help in that regard, to fix this issue. |
thanks @tmikoss @krtschmr decided to use the 2nd method, which is to exclude just the const nodeModulesLoader = environment.loaders.get('nodeModules')
if (!Array.isArray(nodeModulesLoader.exclude)) {
nodeModulesLoader.exclude = (nodeModulesLoader.exclude == null)
? []
: [nodeModulesLoader.exclude]
}
nodeModulesLoader.exclude.push(/actioncable/) |
There are 2 Please see rails/webpacker#2131 (comment) for more discussion. |
I was using rollup together with the javascript library What made the error go away was to use commonjs with named exports.
|
@jakeNiemiec can you think about some permanent solution to this issue, so it won't happen in newly generated app? |
@morgoth Yes, see rails/webpacker#2131 (comment) |
FYI I've submitted this issue as a post in the Rails Forum's May of WTFs because I think it stands to reason this bug will bite people using ActionCable for the first time and leave a pretty bad taste in their mouth. Any feedback about how much of your time was lost to this bug or your general thoughts are welcome! https://discuss.rubyonrails.org/t/actioncable-broken-by-default-in-rails-6-in-prod/74457 |
cc @javan |
fixes rails/rails#35501 fixes rails#2131 fixes rails/rails#36278 fixes rails#2407 fixes rails#2114 fixes rails#1949 fixes rails#1865 fixes rails#1857
fixes rails/rails#35501 fixes #2131 fixes rails/rails#36278 fixes #2407 fixes #2114 fixes #1949 fixes #1865 fixes #1857
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
I ran into a similar looking issue that I suspect shares the same underlying cause. In my case, I get a runtime error in my development build: The fixes proposed by others in this issue assume the use of rails import { createConsumer } from "actioncable";
...
createConsumer("my url"); <-- errors to: import actioncable from "actioncable";
...
actioncable.createConsumer("my url"); <-- no error got my app to run without issue. Hopefully this helps others that run into this. Also if you think there's a more appropriate place for my comment, or maybe it merits its own issue, let me know. |
fixes rails/rails#35501 fixes rails/webpacker#2131 fixes rails/rails#36278 fixes rails/webpacker#2407 fixes rails/webpacker#2114 fixes rails/webpacker#1949 fixes rails/webpacker#1865 fixes rails/webpacker#1857
fixes rails/rails#35501 fixes rails/webpacker#2131 fixes rails/rails#36278 fixes rails/webpacker#2407 fixes rails/webpacker#2114 fixes rails/webpacker#1949 fixes rails/webpacker#1865 fixes rails/webpacker#1857
Steps to reproduce
rails new myapp
) with all the defaultsbin/rails g channel test
Expected behavior
The websocket connection is successful and there are no console errors
Actual behavior
Console error
Uncaught TypeError: r is not a function
in action_cable.js.In my source map the error points to the following line https://github.com/rails/rails/blob/master/actioncable/app/assets/javascripts/action_cable.js#L21
My Theories
It seems that webpacker compiles this file incorrectly (only in production) and doesn't seem to like that the variable is named
_typeof
. I can see there are distinct differences in how the file is compiled in production vs dev (these differences cause dev to work and prod to throw the aforementioned error)If I revert back to the yarn package
actioncable
vs@rails/actioncable
and I revert myconsumer.js
file to use the old import syntax, everything works fine.Things I already tried to fix this:
If my bug is accurate, it stands to reason that perhaps it is not possible to deploy Rails 6 with actioncable in a production environment with the default generated files. I am curious if anyone has shipped a working actioncable feature on a brand new Rails 6 beta2 project with the default files and generators.
System configuration
Rails version: 6.0.0.beta2
Ruby version: 2.6.1
The text was updated successfully, but these errors were encountered: