Can't install TypeScript. npm exited with non-zero code: 1

Please provide the following:

  1. SDK Version:47.0.0
  2. Platforms(Android/iOS/web/all):all

I was trying to install TypeScript to my existing Expo app, but i am unsuccessful.

First I created a tsconfig.json in my root, then I ran npx expo start.
It detected I am trying to use TS, it asked me to install it, and I said yes, but then it always ends up with this error:

√ It looks like you’re trying to use TypeScript but don’t have the required dependencies installed. Would you like to install typescript@^4.6.3? … yes

› Installing 1 SDK 47.0.0 compatible native module using npm

npm install
/ Installing typescript@^4.6.3npm WARN config global --global, --local are deprecated. Use --location=global instead.
/ Installing typescript@^4.6.3npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: react-native-elements@3.4.2
npm ERR! Found: react-native-safe-area-context@4.4.1
npm ERR! node_modules/react-native-safe-area-context
npm ERR! react-native-safe-area-context@“4.4.1” from the root project
npm ERR! peer react-native-safe-area-context@“>= 3.0.0” from @react-navigation/bottom-tabs@6.4.0
npm ERR! node_modules/@react-navigation/bottom-tabs
npm ERR! @react-navigation/bottom-tabs@“^6.4.0” from the root project
npm ERR! 3 more (@react-navigation/drawer, …)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react-native-safe-area-context@“^3.1.9” from react-native-elements@3.4.2
npm ERR! node_modules/react-native-elements
npm ERR! react-native-elements@“^3.4.2” from the root project
npm ERR!
npm ERR! Conflicting peer dependency: react-native-safe-area-context@3.4.1
npm ERR! node_modules/react-native-safe-area-context
npm ERR! peer react-native-safe-area-context@“^3.1.9” from react-native-elements@3.4.2
npm ERR! node_modules/react-native-elements
npm ERR! react-native-elements@“^3.4.2” from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\stesv\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\stesv\AppData\Local\npm-cache_logs\2022-11-22T01_29_54_740Z-debug-0.log

:heavy_multiplication_x: Failed to install typescript@^4.6.3 with error: npm exited with non-zero code: 1
Error: npm exited with non-zero code: 1
Error: npm exited with non-zero code: 1
at ChildProcess.completionListener (R:\iGradePlus\iGradePlus-mobile\node_modules@expo\spawn-async\build\spawnAsync.js:52:23)
at Object.onceWrapper (node:events:642:26)
at ChildProcess.emit (node:events:527:28)
at ChildProcess.cp.emit (R:\iGradePlus\iGradePlus-mobile\node_modules\cross-spawn\lib\enoent.js:34:29)
at maybeClose (node:internal/child_process:1092:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)

at spawnAsync (R:\iGradePlus\iGradePlus-mobile\node_modules@expo\spawn-async\build\spawnAsync.js:17:21)
at NpmPackageManager._runAsync (R:\iGradePlus\iGradePlus-mobile\node_modules@expo\package-manager\build\NodePackageManagers.js:133:51)
at NpmPackageManager.installAsync (R:\iGradePlus\iGradePlus-mobile\node_modules@expo\package-manager\build\NodePackageManagers.js:59:20)
at NpmPackageManager.addWithParametersAsync (R:\iGradePlus\iGradePlus-mobile\node_modules@expo\package-manager\build\NodePackageManagers.js:72:24)
at async installPackagesAsync (R:\iGradePlus\iGradePlus-mobile\node_modules@expo\cli\build\src\install\installAsync.js:82:5)
at async installPackagesAsync (R:\iGradePlus\iGradePlus-mobile\node_modules@expo\cli\build\src\start\doctor\dependencies\ensureDependenciesAsync.js:115:9)
at async Object.ensureDependenciesAsync (R:\iGradePlus\iGradePlus-mobile\node_modules@expo\cli\build\src\start\doctor\dependencies\ensureDependenciesAsync.js:74:13)
at async TypeScriptProjectPrerequisite._ensureDependenciesInstalledAsync (R:\iGradePlus\iGradePlus-mobile\node_modules@expo\cli\build\src\start\doctor\typescript\TypeScriptProjectPrerequisite.js:89:20)
at async TypeScriptProjectPrerequisite.assertImplementation (R:\iGradePlus\iGradePlus-mobile\node_modules@expo\cli\build\src\start\doctor\typescript\TypeScriptProjectPrerequisite.js:55:9)
at async TypeScriptProjectPrerequisite.assertAsync (R:\iGradePlus\iGradePlus-mobile\node_modules@expo\cli\build\src\start\doctor\Prerequisite.js:26:20)

Any idea? I am not sure what steps to take when there are dependencies issues…

Hi @stesvis

It looks like you’re using an old version of npm. Try upgrading. Also make sure you’re using a recent even-numbered version of node (e.g. version 16 or 18)

If that doesn’t fix it, you can try running the following:

npm config set legacy-peer-deps true

You can set it back to the default false again afterwards.

Thanks @wodin but that still gave me headaches.
Eventually I ran npm ls react-native-safe-area-context and found that other packages expected it to be at v3.4.1.

So i manually installed that version and now every time I run npm install <package> I don’t get any more errors.

The problem is that expo complains that I am not using the correct version, but I can’t get the latest because I would have to deal with the other original issue…

OK. Might be worth looking into those things that want an old version of react-native-safe-area-context