網站搜尋

typescript - 為什麼在將本地套件安裝到另一個本地套件時會添加 node_modules?


當我搜尋這個問題的答案時,我有點困惑。

我已經建立了一個 TypeScript/Node.js 套件「firstmodule」。編譯後,DIST 資料夾只包含一些子目錄中的幾個 .js 檔案和一個 index.js 檔案

然而,當將此套件作為依賴增加到另一個應用程式中 yarn add c:\....\firstmodule 時,該套件確實安裝在 c:\...\app\node_modules\firstmodule,但是 firstmodule 的 node_modules 也被安裝了 c:\...\app\node_modules\firstmodule\node_modules\**。為什麼會這樣呢?這會大大增加應用程式的體積。

如何避免這個?查看從 NPM 下載的所有套件,沒有一個安裝了它們的 node_modules。

我想在配置檔裡一定有一個選項,但找不到是哪一個。

謝謝你指導我。

編輯

這裡是一個問題的截圖。我們可以看到我的本地模塊 "@C***\g****" 已經作為依賴成功安裝。然而,它自己的 node_modules 也是如此,而例如 @appolographql 模塊已經安裝在主要項目中。對我來說,這似乎是一個奇怪的問題

這是 firsmodule 的 package.json:

{
    "name": "firstmodule",
    "version": "1.0.0",
    "main": "./dist/index.js",
    "types": "./dist/index.d.ts",
    "license": "MIT",
    "author": {
        "email": "****.com",
        "name": "***"
    },
    "keywords": [
        "Api"
    ],
    "scripts": {
        "build": "tsc",
        "start": "ts-node-dev --respawn src/index.ts",
        "prebuild": "yarn lint:fix && rm -rf dist",
        "lint": "./node_modules/.bin./eslint --ext ts ./src",
        "lint:fix": "yarn lint --fix"
    },
    "devDependencies": {
        "@types/bcryptjs": "^2.4.2",
        "typescript": "^3.6.3"
    },
    "dependencies": {
        "bcryptjs": "^2.4.3",
    },
    "engines": {
        "node": ">=10"
    }
}

而這是 tsconfig

{
    "compilerOptions": {
        "rootDirs": ["src"],
        "strict": true,
        "target": "es6",
        "module": "commonjs",
        "lib": ["dom", "es6", "es2017", "esnext.asynciterable"],
        "sourceMap": true,
        "outDir": "./dist",
        "moduleResolution": "node",
        "declaration": true,
        "composite": false,
        "removeComments": true,
        "noImplicitAny": true,
        "strictNullChecks": true,
        "strictFunctionTypes": true,
        "noImplicitThis": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "strictPropertyInitialization": false,
        "skipLibCheck": true,
        "baseUrl": ".",
        "rootDir": "src",
        "resolveJsonModule": true
    },
    "exclude": ["node_modules"],
    "include": ["./src/**/*.tsx", "./src/**/*.ts"],
    "typedocOptions": {
        "mode": "modules",
        "out": "docs"
    }
}