The TypeScript version compatibility issue arises when compiling the server/server.ts
file using tsx --project tsconfig.json
. It reports formatting issues originating from paths like “../node_modules/i18next/…” and “../node_modules/styled_components/…”.
This problem stems from a mismatch in TypeScript versions. The globally installed TypeScript (tsc
) is version 4.x, while the TypeScript versions required by these packages are 5.x. To address this, upgrading to TypeScript 5.x is necessary.
Initially, attempting to update TypeScript globally with npm install -g typescript
failed, as tsc
remained unaffected. Even after uninstalling with npm uninstall -g typescript
, tsc
persisted, indicating it wasn’t linked to the global npm installation.
Subsequently, trying to upgrade the local TypeScript version specified in package.json
didn’t resolve the issue. So I reverted to TypeScript 4.9.6, as required by react-scripts
.
I began to feel puzzled about the origin of tsc
. Using the command which tsc
, I discovered that it was located in /usr/local/bin
, while the locations for Node.js and npm were /opt/homebrew
. This realization led me to recognize that I had multiple installations of Node.js, npm, and npx on my system.
Despite some efforts, I couldn’t find a method to switch or update tsc
. Consequently, I opted to remove the duplicate installations of Node.js, npm, npx, and tsc
located in /usr/local/bin
.
Below are the steps I’ve undertaken.
# remove
cd /usr/local/bin
sudo rm -rf node
sudo rm -rf npm
sudo rm -rf npx
sudo rm -rf tsc
cd /usr/local/share/man/man1
sudo rm -rf node.1
cd /usr/local/include
sudo rm -rf node
cd /usr/local/lib
sudo rm -rf node_modules
# check remaining files
ls /usr/local/bin | grep node
ls /usr/local/bin | grep npm
ls /usr/local/bin | grep npx
ls /usr/local/bin | grep tsc
# validate removal
which node
which npm
which npx
which tsc
Next, I utilized brew install typescript
to install tsc
, resulting in its relocation to /opt/homebrew
, matching the locations of Node and npm. Upon executing tsc --version
, I was pleased to discover that it had been updated to version 5.x, signifying a successful update.
I utilized the newly installed tsc
to compile the server file once more, and this time, it no longer raised issues regarding node_modules
.