使用npm链接安装npm包会导致TS2307:找不到模块

k2arahey  于 2023-05-29  发布在  其他
关注(0)|答案(1)|浏览(167)

我正在构建一个angular库(clan-auth),其中包含我正在构建的几个Angular项目的公共部分。当我从私有npm Repository安装库时,我可以正常使用它的功能。然而,当我将库与npm link链接时,我得到了Error TS2307: Cannot find module 'clan-auth' or its corresponding type declarations。我想这样做是为了更简单地开发库组件,这样我就可以看到它在其中一个应用程序中实现的样子。
查看nodes-modules文件夹,依赖项似乎安装正确,库上的更改也正确反映在nodes-modules库中

package.json从库:

{
    "name": "clan-auth",
    "version": "0.0.1",
    "publishConfig": {
        "registry": "https://privatNPMRepo"
    },
    "peerDependencies": {
        "@angular/common": "^13.3.0",
        "@angular/core": "^13.3.0",
        "ngx-cookie-service": "^13.1.2",
        "angularx-qrcode": "^13.0.6"
    },
    "dependencies": {
        "tslib": "^2.3.0"
    }
}

我的项目文件结构:

- ...
   - libraries (Angular Workspace)
     - projects
       - auth (the clan-auth library is inside this folder)
   - project (the other angular Project)

对于npm链接,我转到.../libraries/projects/auth并执行npm link,然后我转到.../project并执行npm link clan-auth

olqngx59

olqngx591#

你有没有在项目中添加指向链接库的符号链接?
tsconfig.json中的paths配置:

"compilerOptions": {
 ...
    "paths": {
      "clan-auth": [
        "./node_modules/clan-auth"
      ]
    }
  }

相关问题