Open ProchaLu opened 3 months ago
To deploy to Vercel while using ESM, I had to modify the package.json
to switch from "type": "module"
to "type": "commonjs"
. This can be achieved inside the vercel.json
file by specifying a custom buildCommand
.
Here’s the solution:
"buildCommand": "expo export -p web && sed -i 's/\"type\": \"module\"/\"type\": \"commonjs\"/' package.json",
I tried the workaround but it would only run the sed command locally when running Vercel had automatically activated build command override when it detected turborepo.
Not sure it matters, since Expo/Metro uses CJS internally anyways.vercel build
, not when actually deploying.
I ended up using your patch for expo-server headers. Did you open an issue for that already?
@jancbeck, thx for the follow-up! I didn't open an issue for that
@ProchaLu would be great if you could. This saved me quite a lot of time. In any case thanks!
I ended up using your patch for expo-server headers. Did you open an issue for that already?
@jancbeck, thx for the follow-up! I didn't open an issue for that
No need to open an issue, it's already reported and fixed (in June 2024):
Just hasn't been published yet. Probably the next version will be either @expo/server@0.4.5
or @expo/server@0.5.0
- you'll see the change in build/vendor/vercel.js
at the links below once a new version is published (currently both of these links are broken, because they are not published yet):
If you want to use this fixed version without waiting, just change to the canary version that has been published:
cc @kitten @EvanBacon looks like users are having problems elsewhere that this June 2024 fix to @expo/server
has not been published - in case there's a chance to get a new release published soon-ish.
Minimal reproducible example
https://github.com/ProchaLu/expo-api-router-deployment
Which package manager are you using? (Yarn is recommended)
pnpm
If the issue is web-related, please select the bundler (
web.bundler
in theapp.json
)None
Summary
While the Expo API Router documentation states that ESM (ECMAScript Modules) is not supported, all other ESM-based TypeScript configurations in my project have been working seamlessly. I would like to maintain consistency by using ESM throughout the entire project.
Error
When attempting to deploy the Expo API Router on Vercel, I encounter the following error message:
This is my
app/index.js
fileSwitching to TypeScript throws a
exports not defined
errorEnvironment
expo-env-info 1.2.0 environment info: System: OS: macOS 14.5 Shell: 5.9 - /bin/zsh Binaries: Node: 20.14.0 - /opt/homebrew/opt/node@20/bin/node npm: 10.7.0 - /opt/homebrew/opt/node@20/bin/npm Managers: CocoaPods: 1.15.2 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 23.5, iOS 17.5, macOS 14.5, tvOS 17.5, visionOS 1.2, watchOS 10.5 IDEs: Android Studio: 2022.1 AI-221.6008.13.2211.9619390 Xcode: 15.4/15F31d - /usr/bin/xcodebuild npmPackages: expo: ~51.0.20 => 51.0.20 expo-router: ^3.5.18 => 3.5.18 react: 18.2.0 => 18.2.0 react-dom: ^18.3.1 => 18.3.1 react-native: 0.74.3 => 0.74.3 react-native-web: ^0.19.12 => 0.19.12 npmGlobalPackages: expo-cli: 6.3.2 Expo Workflow: managed