首页 > 解决方案 > tsc 对 yarn add ssh:// 不起作用

问题描述

我创建了一个反应库,我正在尝试将它安装在另一个项目中yarn add ssh://<ssh-repo-address>。该库已成功安装在node_modules文件夹中,但yarn build在脚本中执行的命令prepare不会创建 lib(build) 文件夹。如果我yarn build在安装 lib 后直接在node_modules/my-lib中运行命令,则会创建lib文件夹。这可以通过 tsc 实现吗?

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "outDir": "lib/esm",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "declaration": true,
    "declarationDir": "lib/esm",
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "react"
  },
  "include": [
    "src"
  ],
  "exclude": [
    "**/*.spec.?s",
    "**/*.test.?s",
    "**/*.stories.?s",
    "**/*.stories.?sx",
  ]
}

包.json

{
  ...
  "devDependencies": {
    "@babel/core": "^7.15.5",
    "@storybook/addon-actions": "^6.3.9",
    "@storybook/addon-essentials": "^6.3.9",
    "@storybook/addon-links": "^6.3.9",
    "@storybook/react": "^6.3.9",
    "@types/react": "^17.0.27",
    "babel-loader": "^8.2.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "typescript": "^4.4.3"
  },
  "peerDependencies": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },
  "scripts": {
    "storybook": "start-storybook -p 6006",
    "build-storybook": "build-storybook",
    "build": "yarn build:esm && yarn build:cjs",
    "build:esm": "tsc",
    "build:cjs": "tsc --module commonjs --outDir lib/cjs",
    "prepare": "yarn build"
  },
  "main": "./lib/cjs/index.js",
  "module": "./lib/esm/index.js",
  "types": "./lib/esm/index.d.ts"
}

输出yarn add ssh://<ssh-repo-address>

在此处输入图像描述

标签: typescripttsconfigtsc

解决方案


推荐阅读