Strapi v5 Media Library: can't access property "sort"
Strapi v5 Media Library crashing with "can't access property "sort", n is undefined"? What was reported, what to try in order, and how to check for a fix.
The Liite team6 mnt baca
Short answer
No confirmed fix exists for this error. It was reported on Strapi v5.40.0 with SQLite on a VPS, and the suggestions were to disable plugins or downgrade. Back up your database and uploads, then test the fixes below one at a time, starting with the server logs and the failing network request.
Your Strapi v5 admin panel loads, you open the Media Library, and the page breaks. The browser console shows:
TypeError: can't access property "sort", n is undefined
A thread on the Strapi community subreddit, dated March 2026 with 7 comments, describes this on Strapi v5.40.0 with SQLite on a VPS. The poster says it happens even when the folder list is empty. This article covers what was reported, what is worth testing, and how to check whether a newer release has solved it.
Why it happens
We don't know the root cause, and nobody in the thread confirmed one.
The wording of the error gives a hint. In Firefox-style messages, "can't access property X, Y is undefined" means the code tried to read .sort on a value that is undefined. The name n is most likely a minified variable from the production admin bundle, so it doesn't tell you which variable failed.
The empty-folder detail points the same way. An empty list is a valid state, so the Media Library is probably reading something that never arrives, such as a response field that is missing or a request that failed. That is an inference from the message, not a diagnosis from Strapi's source code.
Possible causes, from most to least plausible given the evidence:
| Possible cause | What you would see | How to test |
|---|---|---|
| A failed or malformed API response | A failing request in the Network tab | Check status and response body |
| A plugin interfering with the admin | Crash disappears with plugins off | Disable plugins, retest |
| A stale or mismatched admin build | Crash after an upgrade | Delete .strapi and rebuild |
| A bug in v5.40.0 itself | Crash on a clean project too | Try a newer patch release |
| Database or migration problem | Errors in the server log | Read the logs, check migrations |
The table is a testing plan, not a list of confirmed causes. Only the second and last items match the fixes people suggested in the thread, and neither was reported as confirmed.
Step-by-step fixes
Change one thing at a time so you know what made the difference.
1. Back up first
- Stop Strapi.
- Copy your SQLite database file somewhere safe.
- Copy your uploads folder.
Back up before downgrading
Downgrading can interact badly with database migrations that have already run. Without a copy of the database file, you may not be able to go back.
2. Check the network tab
- Open your browser's developer tools and switch to the Network tab.
- Reload the Media Library page.
- Look for requests with an error status or an empty response.
- Open the failing request and note its URL, status and response body.
If a request fails, the server log usually shows the real error that the admin panel then trips over.
3. Read the server logs
- Watch your process manager's output, or run Strapi in development mode.
- Open the Media Library.
- Look for database, migration or permission errors at the moment of the crash.
A server-side error is a far better lead than the front-end message.
4. Disable third-party plugins
- Comment out your third-party plugins in the plugins configuration file.
- Restart Strapi.
- Reopen the Media Library.
- If it works, re-enable the plugins one at a time to find the culprit.
This was one of the suggestions in the thread.
5. Rebuild the admin panel
- Stop Strapi.
- Delete the
.strapifolder and your build output. - Run your project's build command again.
- Start Strapi and hard-refresh the browser.
A stale admin bundle that no longer matches the installed packages is a plausible source of undefined values. That is our guess; the thread doesn't confirm it.
6. Update to the latest patch release
If the bug is specific to 5.40.0, a later release may have fixed it. Read the release notes for versions after 5.40.0 and search the issue tracker for the error text before upgrading.
7. Downgrade as a last resort
- Confirm you have the backup from fix 1.
- Pin the last Strapi version that worked for you in
package.json. - Reinstall dependencies.
- Rebuild the admin panel and restart.
This was the other suggestion in the thread, also unconfirmed.
Test on a copy
If you can, try the upgrade or downgrade on a copy of the project first. A failed attempt on a copy costs nothing.
What won't help
- Creating a folder to fill the empty list. The report says the crash happens with an empty folder list, and nobody reported that adding folders fixed it. It's cheap to try, but don't expect much.
- Clearing the browser cache on its own. The error comes from the admin app's logic. One hard refresh is fine, but it's unlikely to be the fix.
- Switching databases just for this. Moving from SQLite to Postgres is a big change, and nothing shows the database is the cause. The report mentions SQLite, which may be a coincidence.
How to check whether it's already fixed
The report is from March 2026, so a newer release may have resolved it. Check the source rather than relying on this article:
- Open the releases page of Strapi's GitHub repository and read the notes for versions after 5.40.0.
- Search the repository's issues, open and closed, for the exact error text and for "Media Library".
- If a closed issue references it, the fixed version is usually noted there.
- Strapi's official documentation also has an upgrade guide for moving between v5 releases.
Checklist before you report it
- Strapi version, from
package.jsonand the admin panel footer - Node version and database type
- Full console stack trace
- The failing network request: URL, status and response body
- Whether the crash survives with all third-party plugins disabled
- Whether it survives a clean rebuild of the admin panel
If nothing works
Open an issue on Strapi's GitHub repository. You can also ask on Strapi's official community channels, but the issue tracker is where maintainers triage bugs. Include the exact error text, your versions and the steps you've already tried.
Title: Media Library crashes with TypeError: can't access property "sort", n is undefined
Strapi version: 5.40.0 (replace with yours)
Node version: <your version>
Database: SQLite
Hosting: VPS, production build
Steps:
1. Log in to the admin panel.
2. Open Media Library.
3. The page breaks and the console shows:
TypeError: can't access property "sort", n is undefined
Notes:
- Happens even with an empty folder list.
- Tried: disabling plugins (result), rebuilding admin (result), updating (result).
- Failing network request: <URL, status, response>
- Server log at the time: <paste lines>Common questions
Does this affect Strapi v4?
The report we found is for v5.40.0, and we have no evidence about v4. Don't assume the same bug applies.
Will I lose my uploaded files?
The crash is in the admin interface, and nothing in the report suggests files were deleted. Back up your uploads and database anyway before changing versions.
Is this caused by running on a VPS?
Unknown. The reporter ran on a VPS, but nothing shows the hosting environment is the cause.
Why does the error say "n" instead of a real variable name?
Production admin bundles are minified, which shortens variable names to single letters. Running Strapi in development mode may give a more readable stack trace.