如何在tsconfig中包含节点模块?

时间:2018-12-14 20:12:28

标签: angular typescript bit-src

我有一些原始的角度打字稿组件,已将其放入私有NPM模块中,以在项目之间共享。

我通常像使用其他npm库一样导入组件,但是当我尝试服务我的应用程序时,我得到./node_modules/@bit/myusername.test.global.test-component/test.component.ts is missing from the TypeScript compilation.

我尝试将我的node_modules/@bit/myusername.test.global.test-component/**/*.ts添加到tsconfig.json中的files,但仍然遇到相同的错误。

    {
      "compileOnSave": false,
      "filesGlob": [
        "**/*.ts", //Local source, this is the default //generated source
        "node_modules/@bit/**/*.ts",  // "./node_modules/justinyoung3231.test.global.test-component/*.ts" //generated source

    ], 

//Add as many directories to the above list as needed
  "compilerOptions": {
    "baseUrl": "./src",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

这是我的私有模块中的package.json

{
  "_from": "@bit/myusername.test.global.test-component",
  "_id": "@bit/myusername.test.global.test-component@1.0.1",
  "_inBundle": false,
  "_integrity": {{removed}},
  "_location": "/@bit/myusername.test.global.test-component",
  "_phantomChildren": {},
  "_requested": {
    "type": "tag",
    "registry": true,
    "raw": "@bit/myusername.test.global.test-component",
    "name": "@bit/myusername.test.global.test-component",
    "escapedName": "@bit%2fmyusername.test.global.test-component",
    "scope": "@bit",
    "rawSpec": "",
    "saveSpec": null,
    "fetchSpec": "latest"
  },
  "_requiredBy": [
    "#USER",
    "/"
  ],
  "_resolved": "https://node.bitsrc.io/myusername.test.global.test-component/-/myusername.test.global.test-component-1.0.1.tgz",
  "_shasum": {{removed}},
  "_spec": "@bit/myusername.test.global.test-component",
  "_where": "/Users/HD/Desktop/_temp/booker",
  "bundleDependencies": false,
  "dependencies": {
    "@angular/core": "~7.0.0"
  },
  "deprecated": false,
  "devDependencies": {},
  "homepage": "https://bitsrc.io/myusername/test/global/test-component",
  "license": "SEE LICENSE IN LICENSE",
  "main": "test.component.ts",
  "name": "@bit/myusername.test.global.test-component",
  "peerDependencies": {},
  "version": "1.0.1"
}

如何在tsconfig中引用这些文件?

1 个答案:

答案 0 :(得分:0)

您应该做几件事:

  1. 在bit.json文件中设置saveDependenciesAsComponents。看here
  2. 在执行bit import时,要带上组件,请执行bit import --skip-npm-install,以避免组件包依赖性。由于节点模块分辨率,这将回退到项目依赖项。

对于那些不了解上下文的人,OP尝试使用bitsrc.io CLI导入角度分量。目前没有使用角度和钻头的收费支持。为了共享组件,它们必须生活在非常相似的角度项目中,因此角度编译器将负责编译。