Repository navigation
package.js not found error with window.console #287
Copy link
Copy link
Open
Description
Hi,
When I use console: window.console instead of console:'sysoutdiv' I see the following error in the web browser console about package.js not being found:
swingjs2.js:13212 j2sApplet exec TensionApplet loadClazz null -- OK
swingjs2.js:9669 xhr.open async=false url=../../../site/swingjs/j2s/core/package.js
swingjs2.js:9709 GET https://dkosovic.github.io/eVibJS/site/swingjs/j2s/core/package.js 404 (Not Found)
send @ swingjs2.js:9709
ajax @ swingjs2.js:9234
J2S.$ajax @ swingjs2.js:11011
J2S.getFileData @ swingjs2.js:11689
Clazz.loadScript @ swingjs2.js:17195
_Loader.loadClass._Loader.loadClass @ swingjs2.js:16951
_Loader.loadPackageClasspath @ swingjs2.js:16901
__loadClazz @ swingjs2.js:13242
__nextExecution @ swingjs2.js:13214
setTimeout
proto._setupJS @ swingjs2.js:13539
proto._init @ swingjs2.js:13380
J2S._Canvas2D @ swingjs2.js:13352
Applet._getCanvas @ swingjs2.js:22036
Applet._get @ swingjs2.js:22011
SwingJS.getApplet @ swingjs2.js:21901
(anonymous) @ Tension.html:39
swingjs2.js:17544 [Java2Script] The required class file
../../../site/swingjs/j2s/core/package.js
was not found.
SyntaxError: Unexpected token '<'
at evaluate (https://dkosovic.github.io/eVibJS/site/swingjs/swingjs2.js:17092:30)
at Clazz.loadScript (https://dkosovic.github.io/eVibJS/site/swingjs/swingjs2.js:17196:5)
at _Loader.loadClass._Loader.loadClass (https://dkosovic.github.io/eVibJS/site/swingjs/swingjs2.js:16951:10)
at _Loader.loadPackageClasspath (https://dkosovic.github.io/eVibJS/site/swingjs/swingjs2.js:16901:14)
at Array.__loadClazz (https://dkosovic.github.io/eVibJS/site/swingjs/swingjs2.js:13242:18)
at __nextExecution (https://dkosovic.github.io/eVibJS/site/swingjs/swingjs2.js:13214:7)
swingjs2.js:17544 SyntaxError: Unexpected token '<' loading ../../../site/swingjs/j2s/core/package.js
swingjs2.js:17544 j2sApplet exec TensionApplet start applet null
swingjs2.js:13212 j2sApplet exec TensionApplet start applet null -- OK
swingjs2.js:9669 xhr.open async=false url=../../../site/swingjs/j2s/java/lang/Class.js
swingjs2.js:17542 transpiler was unknown now 5.0.1-v7 for java.lang.Class
Con.consoleOutput @ swingjs2.js:17542
(anonymous) @ swingjs2.js:17893
ps.println.ps.println$.ps.println$Z.ps.println$I.ps.println$S.ps.println$C.ps.println$O @ swingjs2.js:17869
It seems to be happening at line 17544 in swingjs2.js :
https://github.com/dkosovic/eVibJS/blob/3e9eece2722b8ca5d8729c94f4a04081e3269d7f/site/swingjs/swingjs2.js#L17540-L17545
This was the HTML I was using:
https://github.com/dkosovic/eVibJS/blob/gh-pages/Programs/General/Prog1/Tension.html
I'm not sure if the package.js not being found error is because I'm doing something wrong? The applet is working fine otherwise.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
BobHanson commentedon Oct 15, 2025
issue #287 -- relative path not allowed in Info.j2sPath
BobHanson commentedon Oct 15, 2025
I am not getting that error. It is normal that package.js is not found. This is not supposed to be a problem.
But what I am seeing is that loading from an HTML file that is not within site/ that AjaxURLConnection.js is not allowing the ../../../ business. There is a check there that the file being loaded is within the j2s path. When this file is requested:
"file:/C:/Users/hanso/git/eVibJS/site/swingjs/j2s/General/Prog1/Tension/BrianControl.gif"
and the J2S path is
"../../../site/swingjs/j2s/"
the path is rejected. Basically, the code is not allowing that. But it should, because you are pointing to the j2s directory.
I have corrected this and pushed a new dist/SwingJS-site.zip. Please try that.
Make sure you run build-site.xml after replacing that zip file in the swingjs/ directory.
dkosovic commentedon Oct 16, 2025
Before the new
dist/SwingJS-site.zip, I was having the relative path problems with Firefox only when using the local filesystem, not when served from a web server.With the new
dist/SwingJS-site.zip, I can confirm Firefox is happy when local filesystem is used. Thanks for the fix.Although I don't see an error similar to
Unexpected token '<'error with Firefox when using local filesystem, if I go to the following GitHub Pages URL :[Note: GitHub Pages wasn't the best web site to demonstrate this, as they do some kind of throttling to discourage the downloading of large files, but if you download the page again, the throttling is no longer there, or at least for a period]
In Firefox I see:
SyntaxError: expected expression, got '<' loading ../../../site/swingjs/j2s/core/package.jsWhile in Chrome or Edge I see:
wochristian commentedon Oct 16, 2025
dkosovic commentedon Oct 16, 2025
I asked GitHub Copilot Pro if it could analyze
site/swingjs/j2s/core/package.jsand the log output, given thatj2s/core/package.jsis intentionally not being shipped.It came up with the following options, I'm not suggesting any of the solutions, but think it might be right about the 404 HTML page causing a JavaScript
evalunexpected token '<' syntax error.:
package.jsstub like the following:<script src="../../../site/swingjs/swingjs2.js"></script>line in the HTML file:BobHanson commentedon Oct 16, 2025
BobHanson commentedon Oct 16, 2025
BobHanson commentedon Oct 16, 2025
BobHanson commentedon Oct 16, 2025
Douglas,
Please don't go with the AI solution. I suppose we could just throw in a default blank package.js. Try that first.
At this point I recommend creating a core file that uses the bulk of the classes in your applets. To do this:
On the local test page site/General_Prog1_Tension_Tension_applet.html
click on get _j2sClassList.txt
Optionally edit that to make it more generic. For example, remove these lines:
General/Prog1/Tension/CFrame.js
General/Prog1/Tension/CFrameAnimation.js
General/Prog1/Tension/CFramePanel.js
General/Prog1/Tension/CFramePicture.js
General/Prog1/Tension/CFrameSmallControl.js
General/Prog1/Tension/CUtility.js
General/Prog1/Tension/Tension.js
core/package.js
(Or, alternatively, add more.)
Place this file in your main project directory.
Create the jars/ directory and copy https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/jars/closure_compiler.jar into it
In build_core.xml change the core.name variable to something more meaningful, perhaps:
Run build_core.xml
It should report:
[java] 0 error(s), 5 warning(s)
[delete] Deleting: C:\Users\hanso\git\eVibJS\site\swingjs\js\core\tmp.js
[echo] ... site/swingjs/j2s/core/core_eVibJS.z.js created [1498664 bytes]
BUILD SUCCESSFUL
Take a look at the warnings if you want, but they are never an issue, in my experience. Don't try to remove them.
Now in your Programs/General/Prog1/Tension.html
change
core: "NONE",
to
core: "_eVibJS",
and open
Programs/General/Prog1/Tension.thml
It will open and display essentially instantaneously. The debugger console will show only a handful of .js files opened. You will see:
xhr.open async=false url=../../../site/swingjs/j2s/core/package.js
but there will be no error report. (This file is a holdover from the original "legacy" pre-SwingJS Jmol JavaScript implementation that has a whole series of core files. package.js is used to trigger their loading as "modules" when specific classes are to be loaded. But I have not used it in general SwingJS implementations.)
Noting here that the system was designed to have site/ be listed in .gitignore, and then you would put these up on some other site, not github.io. That site is quite limited in space allowance (1 GB), and I think every time you compile using the clean option, this would result in all 5200+ files in site/ being uploaded in your push.
It seems to me that you could create something like "site-dist" for release and then just put the Programs/ part up on site-release/j2s along with the the core files. You just have to be careful to exercise the code enough that all the necessary files are there. The "get ._j2sclasslist.txt link still works to show what additional files need including if you create your own copy of the test HTML file within site and run that.
(Alternatively, if you don't want to mess with the test files, you can use the one you have and from the developer console run:
J2S._saveFile('_j2sclasslist.txt', Clazz.ClassFilesLoaded.sort().join('\n'))
)
Bob
dkosovic commentedon Oct 16, 2025
I was thinking a student or students at my campus were doing lots of "stupid" with Deep Learning scraping of GitHub Pages, such that Microsoft is enforcing throttling. With other GitHub pages, occasionally get a page that we have detected suspicious activity from your site and we a checking if you are human. I realized after I posted it was probably caching speeding things up when I tried a different page and the throttling was still there. With GitHub pages it currently takes about 40 seconds to download an applet page.
Thanks for explaining the issues with github.io, definitely will host it somewhere else.
Oh I agree.
Thanks for the packaging release tips and how to speed things up. I was too late with getting this project ready for the course that is using the applets for teaching this semester, so have lots of time before next year to sort out the packaging to exercise enough of the code that all the necessary files are packaged up.
The lecturer is very happy, and likes that he can now do CTRL-moueswheel page zoom for presenting that wasn't possible with Edge IE8 compatibility mode and Java plugin.
I was wondering is there a simple way to make the
wheelormousewheelevent bubble up to parent document so that CTRL-moueswheel page zoom works when over the applet? The applet won't need to make use of thewheelormousewheelevent otherwise.dkosovic commentedon Oct 17, 2025
I forgot to respond, regarding that.
With an empty package.js text file (i.e. issuing
touch site/swingjs/j2s/core/package.json linux), it still complains about missing package.js, but the error is much more graceful as it doesn't have any of the unexpected token '<' syntax error stuff.If the package.js text file contains a blank line (i.e. LF, or CR/LF), then there is no error. I didn't try with a single blank space, that might have worked also, but not sure.
dkosovic commentedon Oct 24, 2025
I had a go at creating a
_j2sClassList.txtfile. On the case sensitive Linux filesystem I was using, the file needed to be renamed to_j2sclasslist.txtin order forant -f build-core.xmlto find it.When using
_eVibJSas part of the core name, are similar issues with case sensitive file servers. The generatedsite/swingjs/j2s/core/core_eVibJS.z.jsneeds to be renamedsite/swingjs/j2s/core/core_evibjs.z.js, otherwise get a HTTP status 404 error.After renaming
core_eVibJS.z.js, it is now complaining about a missingswingjs/j2s/java/lang/.jsfile.I know you recommended not to use GitHub Pages, but it is a good site in regard to slow page load testing, with individual files taking hundreds of milliseconds each to load.
I created an empty
.jsfile, i.e. https://dkosovic.github.io/eVibJS/site/swingjs/j2s/java/lang/.js , unfortunately that didn't help.I think I went overboard with the contents of https://github.com/dkosovic/eVibJS/blob/main/_j2sclasslist.txt by including too many classes, but it doesn't have any
java/lang/.jslisted. so shouldn't be causing the missingswingjs/j2s/java/lang/.jsissue.BobHanson commentedon Oct 28, 2025
Yes, the "empty" package.js file would have to have a white-space character in it.
BobHanson commentedon Oct 28, 2025
java.lang.js issue. This is because you have included java.lang.Double.js in your class list file. That particular file (along with Byte.js, Integer.js, etc.) is not used by the SwingJS system. (Actually, it should not be there at all. It is left over from a very early prototype. ) The SwingJS Clazz object declares all of the primitive number type classes and several other java.lang classes itself.
So if you see that .js error, remove the offending file from your j2sclasslist.
BobHanson commentedon Oct 28, 2025
Here is the full list of classes and interfaces that j2sclazz.js declares (I think):
java.lang.AbstractMethodError
java.lang.Appendable
java.lang.ArithmeticException
java.lang.ArrayStoreException
java.lang.Byte
java.lang.Character
java.lang.Character
java.lang.ClassCastException
java.lang.ClassCircularityError
java.lang.ClassFormatError
java.lang.ClassNotFoundException
java.lang.Cloneable
java.lang.CloneNotSupportedException
java.lang.Comparable
java.lang.Double
java.lang.Error
java.lang.Error
java.lang.Exception
java.lang.Float
java.lang.IllegalAccessError
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.IllegalMonitorStateException
java.lang.IllegalStateException
java.lang.IllegalThreadStateException
java.lang.IncompatibleClassChangeError
java.lang.IndexOutOfBoundsException
java.lang.InstantiationError
java.lang.InstantiationException
java.lang.Integer
java.lang.InternalError
java.lang.InterruptedException
java.lang.LinkageError
java.lang.Long
java.lang.Math
java.lang.NegativeArraySizeException
java.lang.NoClassDefFoundError
java.lang.NoSuchFieldError
java.lang.NoSuchFieldException
java.lang.NoSuchMethodError
java.lang.NoSuchMethodException
java.lang.NullPointerException
java.lang.Number
java.lang.NumberFormatException
java.lang.OutOfMemoryError
java.lang.reflect
java.lang.reflect.GenericDeclaration
java.lang.reflect.InvocationHandler
java.lang.reflect.InvocationTargetException
java.lang.reflect.Member
java.lang.reflect.Modifier
java.lang.reflect.UndeclaredThrowableException
java.lang.ReflectiveOperationException
java.lang.Runnable
java.lang.RuntimeException
java.lang.SecurityException
java.lang.Short
java.lang.StackOverflowError
java.lang.StackTraceElement
java.lang.String
java.lang.StringIndexOutOfBoundsException
java.lang.System
java.lang.ThreadDeath
java.lang.Throwable
java.lang.UnknownError
java.lang.UnsatisfiedLinkError
java.lang.UnsupportedClassVersionError
java.lang.UnsupportedOperationException
java.lang.VerifyError
java.lang.VirtualMachineError
java.lang.Void