3

I've been troubleshooting this for a week now and I'm baffled. The crazy part is that this app has been compiling just fine for months and this seems to have just happened spontaneously without changing anything that should have affected this. Come to think of it, I upgraded from WSL to WSL2 and that is roughly the time this started, possibly a coincidence.

Project Structure

/server
 ⚙tsconfig.json

    /dist
       server.js
        /api
            /v1
                index.js
                /accountDataFunctions
                  duplicates.js
                  notations.js
                  ...
                /sqlQueryGeneration
                  selectQuery.js
                  updateQuery.js

    /src
       server.ts
        /api
            /v1
                index.ts
                /accountDataFunctions
                  duplicates.ts
                  notations.ts
                  ...
                /sqlQueryGeneration
                  selectQuery.ts
                  updateQuery.ts

tsconfig.json

// ⚙tsconfig.json
{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "outDir": "./dist",
    "rootDir": "./src",
    "resolveJsonModule": true,
    "removeComments": true,
    "strict": false,
    "baseUrl": "./",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipLibCheck": true,⭐
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node",
    // "watch": true
  },
  "exclude": [
    "node_modules"
  ],
  "include": [
    "src"
  ],
  "watchOptions": {
    "watchFile": "useFsEvents",
    "watchDirectory": "useFsEvents",
    "fallbackPolling": "dynamicPriority"
  }
}
tsc --showFiles
//30x files in this directory (type definitions):
/home/surface/.nvm/versions/node/v14.15.4/lib/node_modules/typescript/lib/lib.es6.d.ts

//20x files in this directory (type definitions):
/mnt/c/Dev/Projects/debtportfol/server/node_modules/@types/node/globals.d.ts

// (this is actually my project root directory)
/mnt/c/Dev/Projects/debtportfol/

//50x files in this directory which are about 35 correct files, and 15 type definitions:
io/server/src/api/v1/generalFunctions/getDateAndTime.ts
/mnt/c/Dev/Projects/debtportfol/server/src/api/v1/generalFunctions/columns.ts
/mnt/c/Dev/Projects/debtportfol/server/node_modules/axios/index.d.ts
/mnt/c/Dev/Projects/debtportfol/server/node_modules/@types/long/index.d.ts

I've read through the official TS docs, I've tried uninstalling and reinstalling, tinkering with the include/exclude statements for hours. I genuinely can't figure out why this just happened seemingly out of the blue.

I've also noticed that the --watch flag seems to have stopped working as well. Again, I've been working on this app for 9 months and none of this has ever been an issue before.

{
    "main": "server.js",
    "scripts": {
        "serve": "tsc && concurrently \"tsc --watch\" \"nodemon dist/server.js\"",
        "start": "tsc && node dist/server.js",
        "startNormal": "node dist/server.js",
        "devstart": "nodemon run dist/server.js",
        "build": "tsc"
    },
    "dependencies": {
        "@stripe/stripe-js": "^1.9.0",
        ...
        "uuid": "^8.3.0"
    },
    "devDependencies": {
        "@types/axios": "^0.14.0",
        ...
        "concurrently": "^5.3.0",
        "nodemon": "^2.0.3",
        "typescript": "^4.2.3"
    }
}

Bob Bass
  • 127
  • 2
  • 16

1 Answers1

1

Come to think of it, I upgraded from WSL to WSL2 and that is roughly the time this started, possibly a coincidence.

At least for the nodemon/--watch functionality, it's no coincidence. See my answer here for details on why. Short answer -- The NTFS filesystem support in WSL2 is quite different than in WSL1, and inotify is not fully supported in WSL2 at this time. If possible, move your code over to somewhere under the ext4 drive (e.g. /home/surface/projects) or keep a separate instance of WSL1 around for this use.

I can't think of a reason for this causing the TSC changes, but it's possible that it will correct those as well.

Regardless, WSL2 performance on NTFS (9P protocol under WSL2) is so atrociously bad right now that you really want to stick to ext4 if at all possible. While I run WSL2 for my daily driver, I keep a WSL1 instance up-to-date for any operations that are even remotely file-intensive on an NTFS drive (e.g. rsync or s3cmd sync operations). For example, just a git clone of the WSL2 Linux kernel project took ~10 seconds under my ext4 /home/user, but more than 10 minutes on /mnt/c/....

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
  • 1
    I haven't 100% verified just yet but reverting from WSL2 to WSL1 has already increased performance time 10x which was a huge problem. I'm pretty sure that the way the OS shares files between the Linux distro and Windows is the culprit. Not I just need to clear a bunch of caches and find out for sure. Not sure why WSL2 is the 'better' version when WSL1 was perfect ad never gave me any trouble. – Bob Bass Mar 09 '21 at 18:02
  • Right, it's fair to assume that a "version 2" would be an improvement over "version1". But really this is a case where both "versions" have a *raison d'etre*. I keep instances of both WSL1 and WSL2 around. WSL1 for any time I need to work with Windows/NTFS filesystems (e.g. I use `s3cmd` to sync my photos directory with S3-compatible storage), and WSL2 for anything that requires more "Linux kernel-like" behavior (e.g. Docker containers or `socat` to create a tap connection). – NotTheDr01ds Mar 09 '21 at 23:57
  • For what it's worth, I was so frustrated by the WSL stuff that I jumped onto the M1 Mac bandwagon. I don't regret it at all. – Bob Bass Jun 16 '21 at 17:51