簡體   English   中英

TSC 正在逆着 tsconfig.json 文件的方向編譯 node_modules 和類型聲明文件

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

我已經解決了一個星期的問題,我很困惑。 瘋狂的部分是這個應用程序已經編譯好幾個月了,這似乎是自發發生的,沒有改變任何應該影響它的東西。 想想看,我從 WSL 升級到了 WSL2,大概就是這個時候開始的,可能是巧合。

項目結構

/📁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

我已經閱讀了官方 TS 文檔,嘗試卸載和重新安裝,修改包含/排除語句幾個小時。 我真的不明白為什么這似乎突然發生了。

我還注意到--watch flag似乎也停止了工作。 再說一次,我已經在這個應用程序上工作了 9 個月,以前這些都不是問題。

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

想想看,我從 WSL 升級到了 WSL2,大概就是這個時候開始的,可能是巧合。

至少對於nodemon / --watch功能來說,這並非巧合。 有關原因詳細信息,請參閱我的答案。 簡短的回答——WSL2 中的 NTFS 文件系統支持與 WSL1 中的完全不同,目前 WSL2 中不完全支持inotify 如果可能,請將您的代碼移動到 ext4 驅動器下的某個位置(例如/home/surface/projects )或保留一個單獨的 WSL1 實例以供此使用。

我想不出導致 TSC 更改的原因,但它也有可能糾正這些。

無論如何,NTFS(WSL2 下的 9P 協議)上的 WSL2 性能現在非常糟糕,以至於您真的想盡可能堅持使用 ext4。 當我為我的日常驅動程序運行 WSL2 時,我會為任何在 NTFS 驅動器上甚至是遠程文件密集型的操作(例如rsyncs3cmd同步操作)保持一個 WSL1 實例的最新狀態。 例如,WSL2 Linux kernel 項目的 WSL2 Linux kernel 項目的git clone僅在我的 ext4 /home/user上花費了大約 10 秒,但在/mnt/c/...上花費了大約 10 秒,但超過了 1.0 分鍾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM