I’m working on an Expo project with TypeScript and I’m encountering an issue when trying to build my project with eas build --platform android
. The error message I’m getting is:
Error: Unable to resolve module ../screens/Blocklists/BlocklistScreen/BlocklistScreen.tsx from /private/var/folders/s9/20yy8r556gq6s8rhw_rjdbzw0000gn/T/eas-build-local-nodejs/c40fa66c-c43e-4bcb-b90d-4b84afe8ace2/build/src/react-view/navigators/BlocklistStackNavigator.tsx:
This error is thrown by the Metro bundler during the build process. However, when I run yarn tsc --noEmit
, there are no errors, which suggests that TypeScript is able to resolve the module correctly.
A more comprehensive extract of my build failing:
[RUN_GRADLEW] - unimodules-app-loader (4.6.0)
[RUN_GRADLEW] > Configure project :react-native-reanimated
[RUN_GRADLEW] Android gradle plugin: 8.2.1
[RUN_GRADLEW] Gradle: 8.6
[RUN_GRADLEW] > Task :app:createBundleReleaseJsAndAssets
[RUN_GRADLEW] warning: Bundler cache is empty, rebuilding (this may take a minute)
[RUN_GRADLEW] (node:55300) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
[RUN_GRADLEW] (Use `node --trace-deprecation ...` to show where the warning was created)
[RUN_GRADLEW] Error: Unable to resolve module ../screens/Blocklists/BlocklistScreen/BlocklistScreen.tsx from /private/var/folders/s9/20yy8r556gq6s8rhw_rjdbzw0000gn/T/eas-build-local-nodejs/be89a36b-79f0-4ace-a72e-0a64e7ae62a2/build/src/react-view/navigators/BlocklistStackNavigator.tsx:
[RUN_GRADLEW] None of these files exist:
[RUN_GRADLEW] * src/react-view/screens/Blocklists/BlocklistScreen/BlocklistScreen.tsx(.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.mjs|.native.mjs|.mjs|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.cjs|.native.cjs|.cjs|.android.scss|.native.scss|.scss|.android.sass|.native.sass|.sass|.android.css|.native.css|.css)
[RUN_GRADLEW] * src/react-view/screens/Blocklists/BlocklistScreen/BlocklistScreen.tsx/index(.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.mjs|.native.mjs|.mjs|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.cjs|.native.cjs|.cjs|.android.scss|.native.scss|.scss|.android.sass|.native.sass|.sass|.android.css|.native.css|.css)
[RUN_GRADLEW] 1 | import { createStackNavigator } from '@react-navigation/stack'
[RUN_GRADLEW] > 2 | import { BlocklistScreen } from '../screens/Blocklists/BlocklistScreen/BlocklistScreen.tsx'
[RUN_GRADLEW] | ^
[RUN_GRADLEW] 3 | import { BlocklistsStackScreens } from './screen-lists/BlocklistsStackScreens'
[RUN_GRADLEW] 4 | import { CreateBlocklistScreen } from '../screens/Blocklists/CreateBlocklistScreen/CreateBlocklistScreen.tsx'
[RUN_GRADLEW] 5 | import { EditBlocklistScreen } from '../screens/Blocklists/EditBlocklistScreen/EditBlocklistScreen.tsx'
[RUN_GRADLEW] Error: Unable to resolve module ../screens/Blocklists/BlocklistScreen/BlocklistScreen.tsx from /private/var/folders/s9/20yy8r556gq6s8rhw_rjdbzw0000gn/T/eas-build-local-nodejs/be89a36b-79f0-4ace-a72e-0a64e7ae62a2/build/src/react-view/navigators/BlocklistStackNavigator.tsx:
[RUN_GRADLEW] None of these files exist:
[RUN_GRADLEW] * src/react-view/screens/Blocklists/BlocklistScreen/BlocklistScreen.tsx(.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.mjs|.native.mjs|.mjs|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.cjs|.native.cjs|.cjs|.android.scss|.native.scss|.scss|.android.sass|.native.sass|.sass|.android.css|.native.css|.css)
[RUN_GRADLEW] * src/react-view/screens/Blocklists/BlocklistScreen/BlocklistScreen.tsx/index(.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.mjs|.native.mjs|.mjs|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.cjs|.native.cjs|.cjs|.android.scss|.native.scss|.scss|.android.sass|.native.sass|.sass|.android.css|.native.css|.css)
[RUN_GRADLEW] 1 | import { createStackNavigator } from '@react-navigation/stack'
[RUN_GRADLEW] > 2 | import { BlocklistScreen } from '../screens/Blocklists/BlocklistScreen/BlocklistScreen.tsx'
[RUN_GRADLEW] | ^
[RUN_GRADLEW] 3 | import { BlocklistsStackScreens } from './screen-lists/BlocklistsStackScreens'
[RUN_GRADLEW] 4 | import { CreateBlocklistScreen } from '../screens/Blocklists/CreateBlocklistScreen/CreateBlocklistScreen.tsx'
[RUN_GRADLEW] 5 | import { EditBlocklistScreen } from '../screens/Blocklists/EditBlocklistScreen/EditBlocklistScreen.tsx'
[RUN_GRADLEW] at ModuleResolver.resolveDependency (/private/var/folders/s9/20yy8r556gq6s8rhw_rjdbzw0000gn/T/eas-build-local-nodejs/be89a36b-79f0-4ace-a72e-0a64e7ae62a2/build/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:112:15)
[RUN_GRADLEW] at DependencyGraph.resolveDependency (/private/var/folders/s9/20yy8r556gq6s8rhw_rjdbzw0000gn/T/eas-build-local-nodejs/be89a36b-79f0-4ace-a72e-0a64e7ae62a2/build/node_modules/metro/src/node-haste/DependencyGraph.js:231:43)
[RUN_GRADLEW] at /private/var/folders/s9/20yy8r556gq6s8rhw_rjdbzw0000gn/T/eas-build-local-nodejs/be89a36b-79f0-4ace-a72e-0a64e7ae62a2/build/node_modules/metro/src/lib/transformHelpers.js:156:21
[RUN_GRADLEW] at resolveDependencies (/private/var/folders/s9/20yy8r556gq6s8rhw_rjdbzw0000gn/T/eas-build-local-nodejs/be89a36b-79f0-4ace-a72e-0a64e7ae62a2/build/node_modules/metro/src/DeltaBundler/buildSubgraph.js:42:25)
[RUN_GRADLEW] at visit (/private/var/folders/s9/20yy8r556gq6s8rhw_rjdbzw0000gn/T/eas-build-local-nodejs/be89a36b-79f0-4ace-a72e-0a64e7ae62a2/build/node_modules/metro/src/DeltaBundler/buildSubgraph.js:83:30)
[RUN_GRADLEW] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[RUN_GRADLEW] at async Promise.all (index 4)
[RUN_GRADLEW] at async visit (/private/var/folders/s9/20yy8r556gq6s8rhw_rjdbzw0000gn/T/eas-build-local-nodejs/be89a36b-79f0-4ace-a72e-0a64e7ae62a2/build/node_modules/metro/src/DeltaBundler/buildSubgraph.js:92:5)
[RUN_GRADLEW] at async Promise.all (index 7)
[RUN_GRADLEW] at async visit (/private/var/folders/s9/20yy8r556gq6s8rhw_rjdbzw0000gn/T/eas-build-local-nodejs/be89a36b-79f0-4ace-a72e-0a64e7ae62a2/build/node_modules/metro/src/DeltaBundler/buildSubgraph.js:92:5)
[RUN_GRADLEW] FAILURE: Build failed with an exception.
[RUN_GRADLEW] * What went wrong:
[RUN_GRADLEW] Execution failed for task ':app:createBundleReleaseJsAndAssets'.
[RUN_GRADLEW] > Process 'command 'node'' finished with non-zero exit value 1
[RUN_GRADLEW] * Try:
[RUN_GRADLEW] > Run with --stacktrace option to get the stack trace.
[RUN_GRADLEW] > Run with --info or --debug option to get more log output.
[RUN_GRADLEW] > Run with --scan to get full insights.
[RUN_GRADLEW] > Get more help at https://help.gradle.org.
[RUN_GRADLEW] BUILD FAILED in 1m 20s
[RUN_GRADLEW] > Task :app:createBundleReleaseJsAndAssets FAILED
[RUN_GRADLEW] 11 actionable tasks: 11 executed
[RUN_GRADLEW] Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
Build failed
Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
npx exited with non-zero code: 1
Error: build command failed.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
➜ Amehmeto git:(main) ✗
Here is the import statement in BlocklistStackNavigator.tsx
:
import { BlocklistScreen } from '../screens/Blocklists/BlocklistScreen/BlocklistScreen.tsx'
And here is what I think is the relevant part of my tsconfig.json
:
{
"compilerOptions": {
"sourceMap": true,
"paths": {
"@/*": [
"./*"
]
},
// ...other options...
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"app.d.ts",
"App.tsx",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
],
"extends": [
"expo/tsconfig.base",
"@tsconfig/react-native/tsconfig.json"
]
}
As for my package.json
:
{
"name": "projectname",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"scripts": "jq '.scripts' package.json",
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web",
"electron:start": "electron electron.js",
"electron:dev": "concurrently "BROWSER=none expo start --web" "wait-on http://localhost:19006 && yarn electron:start"",
"lint:fix": "tsc --noEmit && eslint --fix 'src/**/*.{js,ts,tsx}' && prettier --write 'src/**/*.{js,ts,tsx}'",
"test": "vitest",
"test:prepush": "vitest --run",
"test:cov": "c8 vitest --run",
"prebuild": "npx expo prebuild",
"prebuild:android": "npx expo prebuild --platform android",
"prebuild:ios": "npx expo prebuild --platform ios",
"build": "eas build --platform all",
"build:android": "eas build --platform android",
"build:android:apk": "eas build -p android --profile preview",
"build:ios": "eas build --platform ios",
"build:ios:simulator": "eas build --profile development-simulator --platform ios",
"check:uncommitted": "git diff-index --quiet HEAD || exit 1",
"prepare": "husky install"
},
"lint-staged": {
"*.{js,ts,jsx,tsx}": "yarn lint:fix"
},
"dependencies": {
"@expo/prebuild-config": "^7.0.4",
"@expo/vector-icons": "^14.0.0",
"@expo/webpack-config": "~19.0.1",
"@faker-js/faker": "^8.4.1",
"@react-native-community/datetimepicker": "8.0.1",
"@react-navigation/bottom-tabs": "^6.5.11",
"@react-navigation/native": "^6.1.9",
"@react-navigation/native-stack": "^6.9.17",
"@react-navigation/stack": "^6.3.20",
"@reduxjs/toolkit": "^2.2.1",
"@types/react-redux": "^7.1.33",
"@types/uuid": "^9.0.8",
"date-fns": "^3.3.1",
"eas-cli": "9.1.0",
"electron": "^30.0.3",
"expo": "~51.0.9",
"expo-asset": "^10.0.6",
"expo-background-fetch": "~12.0.1",
"expo-blur": "~13.0.2",
"expo-constants": "~16.0.2",
"expo-dev-client": "~4.0.15",
"expo-device": "~6.0.2",
"expo-linear-gradient": "~13.0.2",
"expo-navigation-bar": "~3.0.4",
"expo-notifications": "~0.28.4",
"expo-status-bar": "~1.12.1",
"expo-task-manager": "~11.8.2",
"formik": "^2.4.5",
"global": "^4.4.0",
"pouchdb-adapter-memory": "^8.0.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.74.1",
"react-native-elements": "^3.4.3",
"react-native-gesture-handler": "~2.16.1",
"react-native-modal-datetime-picker": "^17.1.0",
"react-native-pager-view": "6.3.0",
"react-native-popup-menu": "^0.16.1",
"react-native-reanimated": "~3.10.1",
"react-native-safe-area-context": "4.10.1",
"react-native-screens": "3.31.1",
"react-native-tab-view": "^3.5.2",
"react-native-uuid": "^2.0.1",
"react-native-vector-icons": "^10.0.3",
"react-native-web": "~0.19.6",
"react-redux": "^9.1.0",
"zod": "^3.22.4"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@tsconfig/react-native": "^3.0.2",
"@types/electron": "^1.6.10",
"@types/jest": "^29.5.11",
"@types/pouchdb": "^6.4.2",
"@types/react": "~18.2.79",
"@types/react-test-renderer": "^18.0.7",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"c8": "^9.1.0",
"concurrently": "^8.2.2",
"eslint": "^8.56.0",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.21.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-native": "^4.1.0",
"eslint-plugin-react-refresh": "^0.4.6",
"eslint-plugin-unicorn": "^53.0.0",
"husky": "^8.0.0",
"lint-staged": "^15.2.2",
"pouchdb": "^8.0.1",
"prettier": "3.1.1",
"tailwindcss": "^3.3.7",
"typescript": "~5.3.3",
"vitest": "^1.2.2",
"wait-on": "^7.2.0"
},
"private": true
}
Any ideas why this might be happening and how to fix it?