1

我有一些原始的 angular typescript 组件,我已将它们放入私有 NPM 模块中以在项目之间共享。

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

我尝试在 tsconfig.json 中添加我node_modules/@bit/myusername.test.global.test-component/**/*.tsfiles,但仍然得到同样的错误。

    {
      "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 中引用这些文件?

4

1 回答 1

0

你应该做几件事:

  1. 在您的 bit.json 文件中设置 saveDependenciesAsComponents。看这里
  2. 做的时候bit import,要带上你的组件,这样做bit import --skip-npm-install是为了避免组件包依赖。由于节点模块解析,这将回退到项目依赖项。

对于那些脱离上下文的阅读,OP 正在尝试使用 bitsrc.io CLI 导入角度组件。现在没有使用角度和位的收费支持。为了共享组件,他们必须生活在非常相似的 Angular 项目中,因此 Angular 编译器将负责编译。

于 2018-12-16T09:17:47.280 回答