[UPDATE]
Initially, I resolved this issue by uninstalling tsc
using npm uninstall tsc
(as recommended in the response marked as the answer). However, the problem resurfaced after some time, and eventually, I found success by utilizing Windows Server for Linux (WSL) with VSCode. This solution worked instantly, so that's what I've been using.
My current dilemma involves running the tsc
command through an NPM script:
"scripts": {
"build": "tsc"
},
Executing tsc
in the Windows command terminal works fine, but when I attempt to do it via the NPM script, it fails. Upon running tsc
through the NPM script, I encounter the following error in the command console:
> npm run build
> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1a6971737676376e687f7f5a2b342a342a">[email protected]</a> build
> tsc
'D\skill-tree\node_modules\.bin\' is not recognized as an internal or external command,
operable program or batch file.
node:internal/modules/cjs/loader:928
throw err;
^
Error: Cannot find module 'D:\Documents\~College\~Coding\tsc\bin\tsc'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code 1
npm ERR! path D:\Documents\~College\~Coding\D&D\skill-tree
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c tsc
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\layto\AppData\Local\npm-cache\_logs\2021-06-03T13_19_01_935Z-debug.log
The error message indicates
Error: Cannot find module 'D:\Documents\~College\~Coding\tsc\bin\tsc'
, which I believe is the root cause of the issue since there is no such folder as ~Coding\tsc
. But I'm unsure why the script is trying to access this folder or how to rectify it.
This is my tsconfig file:
{
"compilerOptions": {
"target": "ESNEXT",
"module": "ESNext",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"./src/**/*"
],
"exclude": [
"./node_modules",
"./.vscode",
"./templates"
]
}
And here's my package file:
{
"name": "skill-tree",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc"
},
"author": "Layton Burchell",
"license": "ISC",
"devDependencies": {
"mongodb": "^3.6.9",
"tsc": "^2.0.3",
"typescript": "^4.3.2"
}
}
Lastly, here's the log file:
(log content)
Efforts I've made to resolve the issue include:
- Global installation of typescript using
npm i typescript -g
- Reinstalling typescript locally with
npm i typescript --save-dev
- Attempting to use
npx tsc
instead oftsc
in both the Windows console and NPM script (resulting in the same error as mentioned above).