-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Active Storage with Direct Upload js giving syntax error #36278
Active Storage with Direct Upload js giving syntax error #36278
Comments
+1 |
@modusss Did you find a solution for this? I've been upgrading my app to 6 rc1 and now I'm running into this issue too. |
Hi Colin, Glad you posted, I was about to try to upgrade to 6rc1 also to see if it would make my problem go away. My workaround was to simply put a js listener on the file_field and that did the trick. The only problem is that the page refreshes. I'd like to access DirectUpload directly, but when I put this in my view... If I change the script tag to: Were you able to import DirectUpload? Thx |
@JetsonDavis I'm currently pecking away at the issues, seems like some messed up dependency issues currently. At least for me. The upgrade from 5.2 -> 6 rc1, isn't terrible but there's a bit too much cleanup that isn't noted in the documentation and I'm not entirely sure if it's my environment or if it's a universal thing. For now I'm just pecking away at errors and dependencies. |
Ok, so you're not working on getting DirectUpload to work automagically yet? I'll let you know if I figure anything out! |
@JetsonDavis @modusss After much messing around, uninstalling/reinstalling node_modules and such. I stumbled upon this little gem const { environment } = require('@rails/webpacker')
module.exports = environment
environment.loaders.delete('nodeModules') There has to be a bug somewhere but 12 hours into doing this upgrade to webpacker and I'm done dealing with this crap for today, I've wasted too much work hours on it already. Hopefully this helps, not sure that it will though 🤔 |
@colinrubbert, here is some more info on that: https://github.com/rails/webpacker/blob/54c3ca9245e9ee330f8ca63b447c202290f7b624/docs/v4-upgrade.md#excluding-node_modules-from-being-transpiled-by-babel-loader This was a controversial change that fixes things for some but hurts others. |
@jakeNiemiec that's precisely where I got the solve from! I'm a bit too in the weeds right now to have remembered where I got it from 🤣 |
I tried to add this line and I restarted the server and the error persists. What is your Rails version ? |
Hi, I also tried to do as you and the problem relies on this part:
I guess that this error occurs because of the ES6 is not supported outside the webpack folder ? |
In both cases the javascript error is:
I created a file "direct_uploader.js" and required in application.js as you told. Don't you use a transpiler gem to use ES6 in this section ? |
@modusss So a few things that I've done is completely delete the node_modules, yarn remove active_storage and webpacker, yarn add active_storage and webpacker, yarn install to rebuild the node_modules, add that code snippet to my environments, much messing around cleaning up sprockets and sorting out the new application.js location with webpacker and I'm sure a half dozen other things (I've put roughly 18 work hours into sorting this out). It's been incredibly stressful. What I've noticed too is that it works best if you run The process needs to be worked on. |
@colinrubbert re we talking about the same thing? You are trying to access the DirectUpload js module? |
@JetsonDavis yes and maybe no ¯_(ツ)_/¯ I had the same DirectUpload error as you guys. Then I fixed that, then I had a ton more errors, then I fixed those and so on and so forth until 18hrs later of trial and error I got everything working properly... so far. So yes and maybe no ¯_(ツ)_/¯ I sincerely hope that you don't have to traverse the path I have in the last 48hrs so hopefully they're different issues. |
Yeah, I'm just trying to figure out where to put - import { DirectUpload } from 'activestorage!!!!! |
@JetsonDavis You shouldn't have put it anywhere, it should automagically be put in the place where it belongs. As far as I can tell all of that stuff should be in your From there your // This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels") Could you maybe check and verify all of your dependencies and such are actually there. Not sure your versioning either so my experience could be completely different from yours. |
rails/webpacker#2110 should help solve the initial problem You can hotfix by putting this in your environment.js file: environment.loaders.nodeModules.exclude = /(?:@?babel(?:\/|\\{1,2}|-).+)|regenerator-runtime|core-js/; |
So Colin, a couple of qq's if I may. @rails is the root of my rails app (which I get with 'which ruby')? Also, I don't have a '/packs' folder in /javascripts, just 'application.js' which already has |
With the same app to test I updated Rails version from 5.2.3 -> 6.0.0.rc1 and ruby from 2.4.5 -> 2.6.3p62. As @colinrubbert posted, the solution to do not have this this error is to add: config/webpack/environment.js Now I get into the "debugger" that is by default inserted on added on this js section right after we upload a file:
After that I can see on the rails server the image being uploaded as this:
The problem now to me is that even showing this successful progress through the code in fact this image is not being saved when I click on the button to submit the form and try to see on "show" page. |
@JetsonDavis You can just do a Are you using @modusss Same question, are you solely looking to use ActiveStorage or are you running into the issue on your way to implementing a stable Webpacker environment? I should probably check my image uploads now that I'm on webpacker to make sure those aren't broken, tests did pass before but 🤔 |
@modusss Can you share the POST request from the browser side? You can do this in your dev tools, this is what it looks like in chrome: Also, the params look out of place: {
"blob"=>{
"filename"=>"dsc_0372.jpg",
"content_type"=>"image/jpeg",
"byte_size"=>520866,
"checksum"=>"ud1utlVF2VVtsdllwJzWhg=="
},
"direct_upload"=>{
"blob"=> {
"filename"=>"dsc_0372.jpg",
"content_type"=>"image/jpeg",
"byte_size"=>520866,
"checksum"=>"ud1utlVF2VVtsdllwJzWhg=="
}
}
} |
@colinrubbert I'm using asset pipeline, no node module. Trying to access the .DirectUpload object from js. The man page says to use import statement but that doesn't work and .DirectUpload calls result in function not found?? I am using the same code @modusss opened this thread with - directly from the man page |
Today I created a new rails 6.0.0.rc1 app and ran in to a similar issue. I have barely written any code, just started configuring stuff. On loading any page, I get a delay of a few seconds, and in the logs I get something like this:
Similarly, running However, running
This error re DirectUpload and actiontext leads me to believe the problem is somehow related to this ticket but I'm not sure what's going on. -- |
It should. Can you try with the latest: If anyone still gets breakage, please post |
Upgraded to webpacker 4.0.6 and if I comment out the |
The issue with DirectUpload export failing while webpack compile is resolved in here(rails/webpacker#2116) by @jakeNiemiec Issue is similar to #36368. |
My question was never answered but I'm giving up on ActiveStorage and going to try another solution - Shrine (https://shrinerb.com/). Hopefully ActiveStorage will be more robust in r6. |
@JetsonDavis Did you happen to try and make a scratch Rails 5.2 or Rails 6 app and then install ActiveStorage. It could be a environment configuration issue. I would recommend doing it with Rails 5.2 because Rails 6 default is Webpacker for asset management. It could help you with your configuration for your main app that you're working on. Do a side by side comparison. ActiveStorage install should do 99% of the heavy lifting for ya. |
Thanks Colin. The other issue with ActiveStorage is that you can't rename the file/blob and/or change the file structure in the AWS bucket to create folders which has also driven me towards another solution (again, unless this has changed in r6?) |
@DavidJRobertson, can you tell me if 4.0.7 fixes things. Please update your From your gist, changing this line to |
@jakeNiemiec that's fixed it, thanks! |
@jakeNiemiec Slightly off topic but maybe not. Do you know if this effects production deployments? I deployed my app to heroku for demoing and it's not reading my trix file which is in the node_modules. Just curious if you know if there needs to be a modification for a production environment like heroku. |
@colinrubbert It can, it just depends on those 4 files and the error. If you tag me in a gist, Ill comment there. Also, make sure you are on webpacker 4.0.7. |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
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
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
My goal
1 - Starts to upload to the cloud after the moment it is attached on client side (before clicking on 'update' button)
2 - Integrate the upload view with another third party js library (as uppy)
From rails documentation:
https://edgeguides.rubyonrails.org/active_storage_overview.html#direct-uploads
Expected behavior
Load js files normally
Actual behavior
This line of code is:
var upload = new !(function webpackMissingModule() { var e = new Error("Cannot find module '@rails/activestorage'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(file, url);
My configuration
Rails version: 5.2.3
Ruby 2.4.5
Obs: Active Storage itself is working properly
links
this issue I also posted on stackoverflow:
https://stackoverflow.com/questions/56132477/active-storage-direct-uploader-giving-syntax-error
The text was updated successfully, but these errors were encountered: