简体   繁体   English

在我的服务中找不到自定义 npm package

[英]custom npm package not found in my service

There is a similar post here:这里有一个类似的帖子:

My custom NPM Package is not found , 我自定义的NPM Package没有找到

but that did not resolve my issue.但这并没有解决我的问题。

Could not find a declaration file for module '@dc_microurb/common'.找不到模块“@dc_microurb/common”的声明文件。 '/Users//Projects/ticketing/auth/node_modules/@dc_microurb/common/build/index.js' implicitly has an 'any' type. '/Users//Projects/ticketing/auth/node_modules/@dc_microurb/common/build/index.js' 隐式具有 'any' 类型。 Try npm install @types/dc_microurb__common if it exists or add a new declaration (.d.ts) file containing `declare module '@dc_microurb/common';尝试npm install @types/dc_microurb__common如果存在)或添加包含“declare module '@dc_microurb/common'的新声明 (.d.ts) 文件;

There is no @types/dc_microurb__common and I am unclear as to why it is suggesting to create a new .d.ts file, when that happens automatically during the build process.没有@types/dc_microurb__common并且我不清楚为什么它建议创建一个新的.d.ts文件,当它在构建过程中自动发生时。

This is the package.json file inside my published package:这是我发布的 package 中的 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"
  }
}

Anybody with experience in publishing packages on npm where TypeScript is involved?有人有在 npm 上发布包的经验,其中涉及 TypeScript 吗? I am unclear as to why this package is not being found by my auth service when it is successfully installed inside that service.我不清楚为什么这个 package 在我的 auth 服务中成功安装后没有被找到。

Did I mess up in the way I am exporting inside my common/src/index.ts file?我在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';

Does it all have to be inside a module.exports instead?这一切都必须在module.exports吗?

So after reviewing a few blogs on Medium on how this is done, I noticed a couple of things.因此,在查看 Medium 上有关如何完成此操作的一些博客之后,我注意到了几件事。

  1. Inside my tsconfig.js , this was missing:在我的tsconfig.js中,缺少以下内容:

    /* Advanced Options / "forceConsistentCasingInFileNames": true / Disallow inconsistencies */ /* 高级选项/ "forceConsistentCasingInFileNames": true /不允许不一致 */

So I manually added it in, secondly, I noticed something I meant to remove earlier but forgot.所以我手动添加了它,其次,我注意到我之前想删除但忘了的东西。 So instead of this:所以不是这个:

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

I needed to have it like this:我需要这样:

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

After making those couple of corrections, now my package is available to my auth service.在进行了这对夫妇的更正之后,现在我的 package 可用于我的身份验证服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM