Skip to content

package.js not found error with window.console #287

Open

Description

@dkosovic

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.

Activity

  1. BobHanson commented on Oct 15, 2025

    @BobHanson
    Owner
  2. added a commit that references this issue on Oct 15, 2025
  3. BobHanson commented on Oct 15, 2025

    @BobHanson
    Owner

    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.

    Image

    Make sure you run build-site.xml after replacing that zip file in the swingjs/ directory.

  4. dkosovic commented on Oct 16, 2025

    @dkosovic
    Author

    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.js

    While in Chrome or Edge I see:

    swingjs2.js:17555 [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:17103:30)
        at Object.loadScript (https://dkosovic.github.io/eVibJS/site/swingjs/swingjs2.js:17207:5)
        at Function.loadClass (https://dkosovic.github.io/eVibJS/site/swingjs/swingjs2.js:16962:10)
        at Function.loadPackageClasspath (https://dkosovic.github.io/eVibJS/site/swingjs/swingjs2.js:16912:14)
        at Array.__loadClazz (https://dkosovic.github.io/eVibJS/site/swingjs/swingjs2.js:13248:18)
        at __nextExecution (https://dkosovic.github.io/eVibJS/site/swingjs/swingjs2.js:13220:7)
    
    swingjs2.js:17555 SyntaxError: Unexpected token '<' loading ../../../site/swingjs/j2s/core/package.js
    
  5. wochristian commented on Oct 16, 2025

    @wochristian
  6. dkosovic commented on Oct 16, 2025

    @dkosovic
    Author

    I asked GitHub Copilot Pro if it could analyze site/swingjs/j2s/core/package.js and the log output, given that j2s/core/package.js is 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 eval unexpected token '<' syntax error.
    :

    1. Use a package.js stub like the following:
    // Minimal stub for j2s/core/package.js
    // Prevents loader from getting a 404 HTML page and trying to eval it.
    var J2S = (typeof J2S !== 'undefined' ? J2S : (this.J2S = {}));
    J2S.Globals = J2S.Globals || {};
    // Mark core as registered so subsequent checks skip loading core/package.js
    J2S.Globals["core.registered"] = true;
    
    /* package.js may register package classpaths in full builds.
       This stub is intentionally minimal to avoid loading errors in
       environments where the full package.js is omitted for size.
    */
    1. Insert this small snippet just before the <script src="../../../site/swingjs/swingjs2.js"></script> line in the HTML file:
    <script>
     // Tell the SwingJS loader that core package is already "registered"
     // so it won't try to fetch core/package.js (which you intentionally omit).
     window.J2S = window.J2S || {};
     window.J2S.Globals = window.J2S.Globals || {};
     window.J2S.Globals["core.registered"] = true;
    </script>
    <script src="../../../site/swingjs/swingjs2.js"></script>
    1. modify the loader:
    --- a/site/swingjs/swingjs2.js
    +++ b/site/swingjs/swingjs2.js
    @@ -16902,15 +16902,25 @@ _Loader.loadPackageClasspath = function (pkg, base, isIndex, fSuccess, mode, pt)
       }
       if (base) // critical for multiple applets
         map["@" + pkg] = base;
    -  if (isIndex && !isPkgDeclared && !J2S.getGlobal(pkg + ".registered")) {
    -         // the package idea has been deprecated
    -         // the only package is core/package.js
    -    if (pkg == "java")
    -        pkg = (J2S.Globals["core.registered"] ? null : "core") // JSmol -- moves java/package.js to core/package.js
    -    // not really asynchronous
    -    if (pkg)
    -       _Loader.loadClass(pkg + ".package", null, true, true, 1);
    -  }
    +       if (isIndex && !isPkgDeclared && !J2S.getGlobal(pkg + ".registered")) {
    +               // the package idea has been deprecated
    +               // the only package is core/package.js
    +               if (pkg == "java")
    +                       pkg = (J2S.Globals["core.registered"] ? null : "core"); // JSmol -- moves java/package.js to core/package.js
    +
    +               // If the page or app has explicitly configured j2s.lib.core as "NONE",
    +               // don't attempt to load core/package.js (file intentionally omitted).
    +               try {
    +                       var j2sLib = J2S.getGlobal && J2S.getGlobal("j2s.lib");
    +                       if (j2sLib && (j2sLib.core === "NONE" || j2sLib.core === "none")) {
    +                               pkg = null;
    +                       }
    +               } catch (ignore) {}
    +
    +               // not really asynchronous
    +               if (pkg)
    +                       _Loader.loadClass(pkg + ".package", null, true, true, 1);
    +       }
       fSuccess && fSuccess();
     };

    Why this helps

    • Many pages in your project explicitly set Info.core = "NONE" and/or configure j2sPath and console. With this patch, if a page's j2s.lib global indicates core: "NONE", the loader will not try to fetch core/package.js. That avoids the 404 + SyntaxError you saw without needing to add stubs or edit every HTML page.
  7. BobHanson commented on Oct 16, 2025

    @BobHanson
    Owner
  8. BobHanson commented on Oct 16, 2025

    @BobHanson
    Owner
  9. BobHanson commented on Oct 16, 2025

    @BobHanson
    Owner
    Image
  10. BobHanson commented on Oct 16, 2025

    @BobHanson
    Owner

    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:

    <property name="core.name" value="_eVibJS" />
    

    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

  11. dkosovic commented on Oct 16, 2025

    @dkosovic
    Author

    This would be your browser cache, probably. That page looks great to me

    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.

    Please don't go with the AI solution.

    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 wheel or mousewheel event 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 the wheel or mousewheel event otherwise.

  12. dkosovic commented on Oct 17, 2025

    @dkosovic
    Author

    I suppose we could just throw in a default blank package.js. Try that first.

    I forgot to respond, regarding that.

    With an empty package.js text file (i.e. issuing touch site/swingjs/j2s/core/package.js on 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.

  13. dkosovic commented on Oct 24, 2025

    @dkosovic
    Author

    I had a go at creating a _j2sClassList.txt file. On the case sensitive Linux filesystem I was using, the file needed to be renamed to _j2sclasslist.txt in order for ant -f build-core.xml to find it.

    When using _eVibJS as part of the core name, are similar issues with case sensitive file servers. The generated site/swingjs/j2s/core/core_eVibJS.z.js‎ needs to be renamed site/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 missing swingjs/j2s/java/lang/.js file.

    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.js file, 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/.js listed. so shouldn't be causing the missing swingjs/j2s/java/lang/.js issue.

  14. BobHanson commented on Oct 28, 2025

    @BobHanson
    Owner

    Yes, the "empty" package.js file would have to have a white-space character in it.

  15. BobHanson commented on Oct 28, 2025

    @BobHanson
    Owner

    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.

  16. BobHanson commented on Oct 28, 2025

    @BobHanson
    Owner

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions