我的服务中找不到自定义npm软件包

时间:2020-11-11 19:45:40

标签: node.js typescript npm

这里有一个类似的帖子:

My custom NPM Package is not found

但这不能解决我的问题。

找不到模块'@ dc_microurb / common'的声明文件。 '/用户//项目/票务/auth/node_modules/@dc_microurb/common/build/index.js' 隐式地具有“ any”类型。尝试npm install @types/dc_microurb__common(如果存在)或添加新的声明 (.d.ts)文件包含`声明模块'@ dc_microurb / common';

没有@types/dc_microurb__common,我不清楚为什么建议在构建过程中自动创建新的.d.ts文件。

这是我发布的软件包中的package.json文件:

{
  "name": "@dc_microurb/common",
  "version": "1.0.5",
  "description": "",
  "main": "./build/index.js",
  "types": "./build/index.d.ts",
  "files": [
    "./build/**/*"
  ],
  "scripts": {
    "clean": "del ./build",
    "build": "npm run clean && tsc",
    "pub": "git add . && git commit -m \"Updates\" && npm version patch && npm run build && npm publish"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "del-cli": "^3.0.1",
    "typescript": "^4.0.5"
  },
  "dependencies": {
    "@types/cookie-session": "^2.0.41",
    "@types/express": "^4.17.9",
    "@types/jsonwebtoken": "^8.5.0",
    "cookie-session": "^1.4.0",
    "express": "^4.17.1",
    "express-validator": "^6.6.1",
    "jsonwebtoken": "^8.5.1"
  }
}

有人在涉及TypeScript的npm上发布软件包方面有经验吗?我不清楚为什么在身份验证服务中成功安装该软件包后,我的身份验证服务却找不到该软件包。

我在导出common/src/index.ts文件中的方式时搞砸了吗?

export * from './errors/bad-request-error';
export * from './errors/custom-errors';
export * from './errors/database-connection-error';
export * from './errors/not-authorized-error';
export * from './errors/not-found-error';
export * from './errors/request-validation-error';

export * from './middlewares/current-user';
export * from './middlewares/error-handler';
export * from './middlewares/require-auth';
export * from './middlewares/validate-request';

所有这些都必须放在module.exports内部吗?

1 个答案:

答案 0 :(得分:0)

因此,在回顾了Medium上的一些博客如何做到这一点之后,我注意到了几件事。

  1. 在我的tsconfig.js里面,这不见了:

    / *高级选项 / “ forceConsistentCasingInFileNames”:true / 禁止不一致* /

所以我手动添加了它,其次,我注意到我打算早些删除但忘记了的东西。所以代替这个:

{
  "name": "@dc_microurb/common",
  "version": "1.0.5",
  "description": "",
  "main": "./build/index.js",
  "types": "./build/index.d.ts",
  "files": [
    "./build/**/*"
  ],

我需要像这样:

{
  "name": "@dc_microurb/common",
  "version": "1.0.6",
  "description": "",
  "main": "./build/index.js",
  "types": "./build/index.d.ts",
  "files": [
    "build/**/*"
  ],

进行了几处更正后,现在我的软件包可用于我的 auth 服务。