I'm trying to put a Symfony 2 app in production mode. It all runs fine except for the fact that the compressed single JavaScript file causes errors and makes the site unable to render correctly. I found this through the debug console on the browser:
Uncaught TypeError: undefined is not a function
Uncaught TypeError: Object [object Object] has no method 'treeview'
The first error refers to jQuery plug-ins
The treeview refers to a plugin for jQuery which renders a tree like directory structure.
On the other hand, it all runs fine on dev mode cause it doesn't do the compression and it just includes every file one by one. Can someone help me on this one?
I've found a solution to this, it appears the issue is related to missing semi-colons.
When something is the last statement in a js file a semi-colon isn't required however assetic just joins the files together and only adds a new line.
Check the file which is being included just before the broken plugin javascript and make sure it ends with a semicolon.
Related
I use Bootstrap studio 5 and I published the website directly from it. When I navigate to it (https://my-website-name.bss.design/) I notice that javascript functionalities are not there. There is an error in the console:
script.min.js?h=fb924772e895278c3c5f2d161d9d0ebd:1 Uncaught TypeError: Cannot read properties of undefined (reading 'addEventListener') at script.min.js?h=fb924772e895278c3c5f2d161d9d0ebd:1:649
It's at the first line but the file only has one line (minified) so this is where the problem is:
document.addEventListener("DOMContentLoaded",(function(){[].slice.call(document.querySelectorAll ...
Somehow document is undefined which makes no sense since that file is loaded at the end of the html body just like it should. Can somehow please tell me what the heck is going on here? I can provide the full script.min.js if necessary.
I didn't try anything since the problem itself makes no sense to me and Bootstrap studio automatically minifies javascript without giving me options.
I'm using jQuery 2.2.4. Everything was ok until I done a major renaming. I renamed the main object, from actual application name to "app". I also renamed other things, as I was changing my app name.
Unfortunately jQuery (minified) doesn't work properly now . I noticed it 2 days after. I spotted 2 weird errors. For example:
$('body').on('change','input:not(.error)', function() { });
When input is changed I get an error "cannot read property test of undefined". jQuery was concatenated with my application file. When I moved jQuery to a separate file I got "uncaught reference error: app is not defined" for that event.
I renamed my main object back from app to something specific, but it didn't have any effect. And development version of jQuery works fine. I can't run a diff, because I changed so many things. Either I will find what causes the issue, or I will have to revert and do everything again.
Does anyone know what might cause jQuery to break? I remind that it only doesn't work on the minified, development version of jQuery.
Rails will not let me run JS code, I have these errors
1)
2)
whenever you add JS code, the errors appear.
Some idea why this happening?
Just because you're getting error highlights in your IDE, doesn't necessarily mean your code is wrong. Try running your server, navigate to your site from your browser, and check the developer console. Do you still see javascript errors?
This warning (it is not an error) is being displayed because your IDE thinks that the variable $ is not defined in your code. However, it is not able to find out that $ is a global variable defined in the jQuery library, imported a few lines before.
The IDE is just saying that the presence of that variable is not guaranteed unless you properly import the needed libraries to make it exist (jQuery in this case). Your code should work properly. In order to identify errors in your javascript code, I would recommend you to use the built in console in the web browser.
Strange error here: I have a page that's referencing several JavaScript files. Occasionally, the browser will complain of:
Uncaught SyntaxError: Unexpected end of input
However, it doesn't appear to be due to a missing parent, or malformed JSON. Part of the JavaScript file will load, but the program will just stop loading the rest of the file. Example: half of the file will load, with the other half missing.
Most of the time, the files load and everything works. Any idea why I would occasionally be getting this error, rather than every time (as expected with a missing paren or something similar)? Other things I can check?
EDIT:
This is a Rails project (Rails version 3.2).
The JS files are standalone, and are kept in the pub directory for dev. In other words, they are NOT included in the asset pipeline.
There must be braces not closed properly.The file stops loading whenever the error is encountered and leaves the rest part unloaded as because of error.
You can check this example here
I have dajaxice installed on my python2.6 dist-packages folder, that seems to work alright with importing the stuff. But it throws all kinds of errors, since the django template tags are not being rendered.
invalid property id [Break on this
error] {% for module in
dajaxice_js_functions %}\n
Makes sense, so I tried putting the js into HTML straight, which solves some of the problems of the templatetags, but gets messed up again, probably since its looking for dajaxice_core_loop.js
invalid property id
[Break on this error] ,\n
I kept on uncommenting JS that throws me errors, but here i stripped it down to an extent that it is not working at all (duh). Because when I recreate the example with the button and hit the button i get:
Dajaxice.MYAPP is undefined
of course, MYAPP is my specific application that holds the ajax.py
I guess I am doing it all wrong, but I can't really tell from the documentation what that might be specifically.
Found that I shoulnd't have configured that Nginx serves my js statically, resolved!
Quick note: on the Django development server I had to place the Dajaxice URL entry before the static media so it could parse the javascript correctly.