Type module (ESM) incompatible with EAS build
- Dominant language
- TypeScript
- Stars
- 1.4k
- Forks
- 236
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 91
Description
### Build/Submit details page URL
https://expo.dev/accounts/loco/projects/bnm7d25/builds/0ba703f7-d5c2-4812-8ada-95874115e8a0
### Summary
Build an app on EAS doesn't work if the project is setup to with `"type": "module"` in the `package.json`.
I _think_ that this is because the EAS build checks if there is an `metro.config.js`, and if there isn't it creates it itself. This however won't work with `"type": "module"` since it will be treated as an esm file.
Locally this works for us since we have a `metro.config.cjs` file. But it seems like EAS build creates `metro.config.js` even when there is an `metro.config.cjs`.
**Workaround:** our current workaround is to include a symlink from `metro.config.js` to `metro.config.cjs`. This allows the build to go thru...
### Managed or bare?
Managed
### Environment
```text
expo-env-info 1.0.2 environment info:
System:
OS: macOS 13.3.1
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
Yarn: 1.22.19 - ~/coding/loco/order/node_modules/.bin/yarn
npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
Watchman: 2023.05.01.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.12.0 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
IDEs:
Xcode: 14.3/14E222b - /usr/bin/xcodebuild
npmPackages:
expo: ^48.0.0 => 48.0.17
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
react-native: 0.71.8 => 0.71.8
npmGlobalPackages:
expo-cli: 6.0.1
Expo Workflow: managed
```
```text
✔ Validating global prerequisites versions passed
✔ Checking for incompatible packages passed
✔ Checking for conflicting global packages in project passed
✔ Verifying prebuild support package versions are compatible passed
✔ Checking dependency versions for compatibility with the installed Expo SDK passed
✔ Validating Expo Config passed
✔ Checking package.json for common issues passed
Didn't find any issues with the project!
```
### Error output
```text
Error: @build-script-error-begin
Error loading Metro config and Expo app config: require() of ES Module /Users/expo/workingdir/build/metro.config.js from /Users/expo/workingdir/build/node_modules/metro-config/node_modules/import-fresh/index.js not supported.
metro.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename metro.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/expo/workingdir/build/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
Make sure your project is configured properly and your app.json / app.config.js is valid.
If you are using environment variables in app.config.js, verify that you have set them in your EAS Build profile configuration or secrets.
@build-script-error-end
at /Users/expo/workingdir/build/node_modules/expo-updates/scripts/createManifest.js:52:11
Command PhaseScriptExecution failed with a nonzero exit code
```
### Reproducible demo or steps to reproduce from a blank project
1. Create a new blank project
2. Add `"type": "module"` to `package.json`
3. Build on EAS
4. ???
5. :boo
Contributor guide
Assessment
This issue has not been assessed yet.