Skip to content

Conversation

@tarikfp
Copy link
Contributor

@tarikfp tarikfp commented Jan 19, 2026

Summary

Fix ESM module compatibility issues that cause build failures during EAS builds.

Issues Fixed

Error 1: Cannot use import statement outside a module

Cannot use import statement outside a module

The voltra/build/server.js uses ESM syntax (import/export) but Node.js treats it as CommonJS because there's no package.json with "type": "module" in the build/ directory.

Error 2: Cannot find module 'voltra/server'

Error: Cannot find module 'voltra/server'
require() of ES Module .../voltra/build/server.js not supported.
Instead change the require of server.js to a dynamic import()

Static import of voltra/server in the plugin fails when compiled to CommonJS.

Fix

  1. Added postprepare script to create build/package.json with {"type": "module"}
    • This survives expo-module rebuilds (unlike a static file that gets cleared)
    • Marks the build directory as ESM module
  2. Changed static import to dynamic import in prerenderWidgetState function

Changes

  • package.json - Added postprepare script to create ESM marker after builds
  • plugin/src/features/ios/files/swift/prerender.ts - Dynamic import for ESM compatibility

Checklist

  • Follows conventional commits
  • Backwards compatible
  • No breaking changes
  • Survives expo-module rebuild cycles

@vercel
Copy link

vercel bot commented Jan 19, 2026

@tarikfp is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

@V3RON
Copy link
Contributor

V3RON commented Jan 19, 2026

Please split the pull request into two: one for the target name and a second for the ESM. The first change introduces a new feature, the second is a fix. They should live as separate commits on the main branch.

@tarikfp tarikfp force-pushed the fix/ios-build-esm-compatibility branch 2 times, most recently from a0e0af7 to 5dae58a Compare January 19, 2026 13:12
@tarikfp tarikfp changed the title fix: ESM module compatibility and configurable target name fix: ESM module compatibility for EAS builds Jan 19, 2026
@V3RON
Copy link
Contributor

V3RON commented Jan 20, 2026

There is one issue: when you build your module using the expo-module CLI, the build directory is cleared, so the package.json is removed. Eventually, I plan to extract the renderer into a separate package, but for now, I believe we can use a post-prepare hook to recreate this package.json.

"postprepare": "echo '{\"type\": \"module\"}' > build/package.json",

1. Added postprepare script to create build/package.json with {"type": "module"}
   This marks the build/ directory as ESM and survives expo-module rebuilds
2. Changed static import to dynamic import for voltra/server in prerender.ts

Fixes build errors during EAS builds:
- "Cannot use import statement outside a module"
- "Cannot find module 'voltra/server'"
@tarikfp tarikfp force-pushed the fix/ios-build-esm-compatibility branch from 5dae58a to 69a1336 Compare January 20, 2026 13:30
@tarikfp
Copy link
Contributor Author

tarikfp commented Jan 20, 2026

There is one issue: when you build your module using the expo-module CLI, the build directory is cleared, so the package.json is removed. Eventually, I plan to extract the renderer into a separate package, but for now, I believe we can use a post-prepare hook to recreate this package.json.

"postprepare": "echo '{\"type\": \"module\"}' > build/package.json",

Right, updated the PR. voltra/server issue has an ugly fix for now, but extraction would be good if it's already planned 👍🏻

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants