Skip to content
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

[BUG] JavaScript loading issue #410

Closed
1 task done
ahavriluk opened this issue Jan 19, 2024 · 14 comments
Closed
1 task done

[BUG] JavaScript loading issue #410

ahavriluk opened this issue Jan 19, 2024 · 14 comments

Comments

@ahavriluk
Copy link

ahavriluk commented Jan 19, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Loading JavaScript produces error in browser console:

Refused to execute script from 'https://REDACTED/login/selectchallenge?redirect_url=/js/core/merged-template-prepend.js?v%3D4c410a93-0' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

This issue has beed addressed lately resulting in multiple commits but it is still not fixed. I am running the latest image in Uraid OS in a docker container.

Expected Behavior

No response

Steps To Reproduce

  1. Two-way authentication app is enabled
  2. Login with username/password without MFA setup yet
  3. Select "Setup two-factor authentication" button

Environment

- OS: Unraid
- How docker service was installed: Using nextcloud template and image from lscr.io/linuxserver/nextcloud

CPU architecture

x86-64

Docker creation

irelavant

Container logs

text  error  warn  system  array  login  

https://www.linuxserver.io/donate/

───────────────────────────────────────
GID/UID
───────────────────────────────────────

User UID:    99
User GID:    100
───────────────────────────────────────

using keys found in /config/keys
**** The following site-confs have extensions other than .conf ****
**** This may be due to user customization. ****
**** You should review the files and rename them to use the .conf extension or remove them. ****
**** nginx.conf will only include site-confs with the .conf extension. ****
/config/nginx/site-confs/default.conf.bak
[custom-init] No custom files found, skipping...
[ls.io-init] done.
[migrations] started
[migrations] 01-nginx-site-confs-default: skipped
[migrations] 02-default-location: skipped
[migrations] done
usermod: no changes
───────────────────────────────────────

      ██╗     ███████╗██╗ ██████╗ 
      ██║     ██╔════╝██║██╔═══██╗
      ██║     ███████╗██║██║   ██║
      ██║     ╚════██║██║██║   ██║
      ███████╗███████║██║╚██████╔╝
      ╚══════╝╚══════╝╚═╝ ╚═════╝ 

   Brought to you by linuxserver.io
───────────────────────────────────────

To support LSIO projects visit:
https://www.linuxserver.io/donate/

───────────────────────────────────────
GID/UID
───────────────────────────────────────

User UID:    99
User GID:    100
───────────────────────────────────────

using keys found in /config/keys
**** The following site-confs have extensions other than .conf ****
**** This may be due to user customization. ****
**** You should review the files and rename them to use the .conf extension or remove them. ****
**** nginx.conf will only include site-confs with the .conf extension. ****
/config/nginx/site-confs/default.conf.bak
[custom-init] No custom files found, skipping...
[ls.io-init] done.
[migrations] started
[migrations] 01-nginx-site-confs-default: skipped
[migrations] 02-default-location: skipped
[migrations] done
usermod: no changes
───────────────────────────────────────

      ██╗     ███████╗██╗ ██████╗ 
      ██║     ██╔════╝██║██╔═══██╗
      ██║     ███████╗██║██║   ██║
      ██║     ╚════██║██║██║   ██║
      ███████╗███████║██║╚██████╔╝
      ╚══════╝╚══════╝╚═╝ ╚═════╝ 

   Brought to you by linuxserver.io
───────────────────────────────────────

To support LSIO projects visit:
https://www.linuxserver.io/donate/

───────────────────────────────────────
GID/UID
───────────────────────────────────────

User UID:    99
User GID:    100
───────────────────────────────────────

using keys found in /config/keys
**** The following site-confs have extensions other than .conf ****
**** This may be due to user customization. ****
**** You should review the files and rename them to use the .conf extension or remove them. ****
**** nginx.conf will only include site-confs with the .conf extension. ****
/config/nginx/site-confs/default.conf.bak
[custom-init] No custom files found, skipping...
[ls.io-init] done.
Copy link

Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.

@teambvd
Copy link

teambvd commented Jan 22, 2024

This isn't an issue with the LSIO nextcloud image (LSIO packaging of the application), but one you're experiencing with the twofactor_totp nextcloud app - I'd recommend taking a look at the TOTP app repo for assistance on this one.

Quick search there pulls up a couple hits, including this one; just noting as it might be helpful - asking there would be your best bet.

@ahavriluk
Copy link
Author

Thank you! I have moved to nextcloud-aio image and the issue doesn't exist there using the same TOTP.

@joomlaproffs
Copy link

joomlaproffs commented Jan 23, 2024

I have this exact issue as @ahavriluk explains in first post. I am not using the TOTP plugin at all (it's disabled).

Screenshot 2024-01-24 082617

This is a new fresh install.

Also sharing a folder from the browser does not work as the sidebar just loads forever. Might be related to above issue.

image

Everything seems to work nice from Android app.

@JcMinarro
Copy link

I have the same issue when sharing a folder and I already reported nextcloud/server#43049
It looks like for some reason the file /js/core/merged-template-prepend.js doesn't exist

@ahavriluk
Copy link
Author

ahavriluk commented Jan 25, 2024

I have the same issue when sharing a folder and I already reported nextcloud/server#43049 It looks like for some reason the file /js/core/merged-template-prepend.js doesn't exist

The file definitely exist in my case. If you examine the latest PRs, they were messing up with js and mime types. Somethings to look at since it is not working. I am pretty positive it is the image packaging related issue, since other images like nextcloud-aio don't have this problem.

@DivineDominion
Copy link

DivineDominion commented Feb 3, 2024

Update 2024-02-04: The ''''fix''''' I propose makes other things worse, retracted

old reply

I found a way to modify the default.conf to try to load from Nextcloud's appdata/js directory.

I hard-coded my instance id here, appdata_och3cf62rsmv, and the two step fallback that works thus far is this:

# Serve static files
location ~* \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ {
    try_files $uri $uri/ @fallback;
    add_header Cache-Control "public, max-age=15778463, $asset_immutable";
    access_log off;     # Optional: Don't log access to assets

    location ~ \.wasm$ {
        default_type application/wasm;
    }
}

# Custom fallback logic
location @fallback {
    # Handle JS files
    location ~* \.js$ {
        try_files /data/appdata_och3cf62rsmv/js/$uri /index.php$request_uri =404;
    }

    # Handle CSS files
    location ~* \.css$ {
        try_files /data/appdata_och3cf62rsmv/css/$uri /index.php$request_uri =404;
    }

    # Fallback for other file types (you could extend this concept as needed)
    location ~* \.(?:mjs|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ {
        try_files /index.php$request_uri =404;
    }
}

If lookup of the file fails, it tries to map e.g. the missing /core/merged-template-prepend.js to /data/appdata_och3cf62rsmv/js/core/merged-template-prepend.js.

The sidebar now loads just fine. But this weird hack doesn't seem like it's really doing what it is supposed to do.

@joshtrichards
Copy link

joshtrichards commented Feb 3, 2024

@DivineDominion What did you default.conf look like before that? Because the try_files line doesn't look right. The one in the repo here looks more reasonable relative to what we document[1].

# Serve static files
location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463, $asset_immutable";
access_log off; # Optional: Don't log access to assets
location ~ \.wasm$ {
default_type application/wasm;
}
}

[1] https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html

@DivineDominion
Copy link

I take everything back -- after a day the Nextcloud nginx serves Bad Request errors :)

@joshtrichards I used the current one on master as reference.

Wanted to get double fallbacks. Got the syntax wrong it seems

@LinuxServer-CI
Copy link
Collaborator

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

@johnsanc314
Copy link

I know this is closed, but I also had this same issue with the missing /js/core/merged-template-prepend.js file. After some tinkering with the requests, I noticed that /index.php/js/core/merged-template-prepend.js returns the file just fine.

I looked closer at my default.conf nginx config, and noticed I had this:

    # Serve static files
    location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map|ogg|flac)$ {
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463, $asset_immutable";
        access_log off;     # Optional: Don't log access to assets

        location ~ \.wasm$ {
            default_type application/wasm;
        }

        location ~ \.js$ {
            default_type text/javascript;
        }

        location ~ \.mjs$ {
            default_type text/javascript;
        }
    }

The culprit seemed to be this part:

        location ~ \.js$ {
            default_type text/javascript;
        }

Once I removed that, everything worked just fine and the file was accessible without index.php

After looking closer at the response headers for that file I see its set to application/javascript instead of the correct text/javascript

@homerr
Copy link
Member

homerr commented Apr 1, 2024

Just had a look and that block isn't in our default config in the container, is yours using a current default.conf or is it custom/outdated?

@homerr
Copy link
Member

homerr commented Apr 2, 2024

Going to close this off - there's been quite a few bugs in the 28 release of NC that have been slowly weeded out, with a few changes of our own mixed in (and reversed) I suspect this is OK now. Make sure you're using the most up to date versions of the default.conf file in the container.

Reopen if issues are still there!

@dathbe
Copy link

dathbe commented Jul 24, 2024

My solution was here:
nextcloud/server#44128 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

10 participants