Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@markkaylor
Copy link
Contributor

@markkaylor markkaylor commented Nov 14, 2025

What does it do?

Replace static import with dynamic import for file-type package to support ESM-only modules in both CommonJS/ESM builds.

The maintainer mentions this approach here: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

Why is it needed?

file-type is ESM-only and lacks CommonJS exports. When Strapi builds its CommonJS output, the bundler fails to transform the static import to require(). This breaks app startup on Node.js < 22, which has stricter ESM/CommonJS interop. Dynamic imports work at runtime in both module formats.

How to test it?

You will need to be able to switch node versions with something like https://github.com/nvm-sh/nvm

Switch to node 20 (nvm install 20 if it's not already installed. nvm use 20 to use it, node -v to confirm)
Create a strapi app with npx create-strapi-app@0.0.0-experimental.f9ca9ac9518346cac58a4a3a576bc9d9d795570d test-fix --quickstart
Update the config in config/plugins.js:

upload: {
    config: {
      security: {
        deniedTypes: ['video/*'],
      }
    }
  }

Run npm run develop there should NOT be an error
Go to the media library and try to upload a video, it should be rejected
Try to upload other file types not in the deniedTypes list, it should work

Test the same for all node versions up to 24

Related issue(s)/PR(s)

Resolves #24829

@vercel
Copy link

vercel bot commented Nov 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
contributor-docs Ready Ready Preview Comment Nov 14, 2025 11:27am

@markkaylor markkaylor self-assigned this Nov 14, 2025
@markkaylor markkaylor added pr: fix This PR is fixing a bug source: core:upload Source is core/upload package labels Nov 14, 2025
@markkaylor markkaylor added this to the 5.31.1 milestone Nov 14, 2025
@trunk-io
Copy link

trunk-io bot commented Nov 14, 2025

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

Copy link
Contributor

@mathildeleg mathildeleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, well done ✅

Copy link
Contributor

@Adzouz Adzouz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and it works now, good job 👏

@araksyagevorgyan
Copy link
Contributor

araksyagevorgyan commented Nov 14, 2025

I tested further, LGTM 🚀

@markkaylor markkaylor merged commit 70ef79a into develop Nov 14, 2025
134 checks passed
@markkaylor markkaylor deleted the fix/file-type-support-commonjs branch November 14, 2025 14:26
chaitya-titan pushed a commit to chaitya-titan/strapi that referenced this pull request Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: fix This PR is fixing a bug source: core:upload Source is core/upload package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strapi fails to start: "No 'exports' main defined in file-type package" error on version 5.31.0

5 participants