简体   繁体   中英

TSC is compiling node_modules and type declaration files against the direction of the tsconfig.json file

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

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 (eg /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 (eg 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/... .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM