After updating to the latest version of sweetalert2 via bower, chrome gives me the following error:
Uncaught SyntaxError: Unexpected token export at the line export default sweetAlert. I have not received this error with previous versions.
Hi @thisisevan, which file are you pulling into your project?
3.1.1. I can try via the cdn now too.
Which specific file though? I believe you're using a file intended for bundling tools such as browserify. Make sure you're referencing dist/sweetalert2.js or dist/sweetalert2.min.js
I'm running this through rails and rails-assets, which takes a bower package and turns it into a rails gem (which seems like the problem) so I can't specify the precise file name, however I'm assuming it uses dist/sweetalert.js. I haven't had a problem with rails-assets before, but if the bower package works on your end I'll find another solution and close the issue.
According to this github issue it's possible to manually choose the file. The way this projects bower.json is setup (as per the official bower docs) it references the source file which is what's causing the issue. You actually want a specific build.
That does seem to be the problem. The gem is pulling in sweetalert2.common.js instead of sweetalert2.js. Unfortunately I can't use the fix you referenced because the gem only pulled in the common.js file, so I can't manually specify anything else.
I just switched over to using the cdn and everything is working again. I'll be using this until I have time to look further into rails-assets.
No problem, let me know if there's anything that can be done that will benefit others that encounter this issue!
Thank you @samturrell for filling me in, I really appreciate it.
I currently have the exact same problem. rails-assets is not including the dist/sweetalert2.js which seems to be the problem.
I think it relates to the bower.json: "main": ["src/sweetalert2.js", "src/sweetalert2.scss", "dist/sweetalert2.css"],. It looks to me that rails-assets is not including the dist/sweetalert2.js because it is missing in there. Is there any specific reason that the dist version is not included there?
Thanks,
Atrox
Hi @Atrox , I believe this is because the npm specification for package.json says that the main should not include compiled files. However I would agree that the base compiled version should be included.
Hi @samturrell ,
thank you for the fast response. I'm talking about the bower.json. As far as I know, bower is mostly for client-side stuff, so it seems to me it should definitively include the compiled versions.
Thanks,
Atrox
Hi @Atrox, sorry i meant bower.json (it's been a long day)
As defined in the bower spec:
Use source files with module exports and imports over pre-built distribution files.
Hmm, you are right. Then it is probably just rails-assets fault for not including the other files too. I will just stick to an older version then.
Thank you for the help :)!
From the Bower documentation for main section:
Do not include minified files.
Minified, not compiled. I think dist/sweetalert2.js is what we need in bower.json:
Thank you @limonte!
Rails Assets is including the correct file now.
Great!
Most helpful comment
Thank you @limonte!
Rails Assets is including the correct file now.