LaytonGB
LaytonGB

Reputation: 1404

NPM script to build typescript not working

[UPDATE]

This issue was originally solved by uninstalling tsc with npm uninstall tsc (as suggested by the marked answer). However, the issue came back and after a long time had passed I tried using Windows Server for Linux (WSL) with VSCode. It did the trick immediately, so that is the solution I've stuck with.


I am having an issue running the tsc command using an NPM script:

"scripts": {
  "build": "tsc"
},

Running tsc in the windows command terminal runs fine, but running tsc using the NPM script does not. When I run tsc in the NPM script, I get the following in the command console:

> npm run build

> [email protected] 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

I have noted that it says Error: Cannot find module 'D:\Documents\~College\~Coding\tsc\bin\tsc' and I think that is the root of the problem because such a folder ~Coding\tsc does not exist, but I don't understand why the script is attempting to access the folder, nor do I know how to fix it.

Here 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"
  ]
}

Here is 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"
  }
}

Here is the log file:

0 verbose cli [
0 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
0 verbose cli   'C:\\Users\\layto\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
0 verbose cli   'run',
0 verbose cli   'build'
0 verbose cli ]
1 info using [email protected]
2 info using [email protected]
3 timing config:load:defaults Completed in 2ms
4 timing config:load:file:C:\Users\layto\AppData\Roaming\npm\node_modules\npm\npmrc Completed in 2ms
5 timing config:load:builtin Completed in 2ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 1ms
8 timing config:load:file:D:\Documents\~College\~Coding\D&D\skill-tree\.npmrc Completed in 0ms
9 timing config:load:project Completed in 0ms
10 timing config:load:file:C:\Users\layto\.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:C:\Program Files\nodejs\etc\npmrc Completed in 1ms
13 timing config:load:global Completed in 1ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setUserAgent Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 8ms
19 verbose npm-session cdea02db6803097a
20 timing npm:load Completed in 19ms
21 timing command:run-script Completed in 105ms
22 verbose stack Error: command failed
22 verbose stack     at ChildProcess.<anonymous> (C:\Users\layto\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\promise-spawn\index.js:64:27)
22 verbose stack     at ChildProcess.emit (node:events:378:20)
22 verbose stack     at maybeClose (node:internal/child_process:1067:16)
22 verbose stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
23 verbose pkgid [email protected]
24 verbose cwd D:\Documents\~College\~Coding\D&D\skill-tree
25 verbose Windows_NT 10.0.19042
26 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\layto\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
27 verbose node v15.8.0
28 verbose npm  v7.5.2
29 error code 1
30 error path D:\Documents\~College\~Coding\D&D\skill-tree
31 error command failed
32 error command C:\Windows\system32\cmd.exe /d /s /c tsc
33 verbose exit 1

I have tried:

Upvotes: 3

Views: 2814

Answers (1)

Christian
Christian

Reputation: 1260

You don't need the tsc package (which is listed in your devDependencies). It's not from Microsoft. The tsc command line tool comes with the typescript node package.

So uninstall tsc and retry.

Upvotes: 1

Related Questions