首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在我的服务中找不到自定义npm包

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

Stack Overflow用户
提问于 2020-11-11 19:45:40
回答 1查看 251关注 0票数 0

这里有一个类似的帖子:

My custom NPM Package is not found

但这并没有解决我的问题。

找不到模块“@dc_microurb/common”的声明文件。'/Users//Projects/ticketing/auth/node_modules/@dc_microurb/common/build/index.js‘隐式地具有“任意”类型。如果存在npm install @types/dc_microurb__common,可以尝试使用它,或者添加一个新的声明(.d.ts)文件,其中包含‘`declare模块’@dc_microurb/ module‘;

这里没有@types/dc_microurb__common,我不清楚为什么它建议创建一个新的.d.ts文件,而这在构建过程中会自动发生。

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

代码语言:javascript
复制
{
  "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"
  }
}

谁有在npm上发布软件包的经验,其中涉及TypeScript?我不清楚为什么我的auth服务没有找到这个包,当它成功地安装在该服务中时。

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

代码语言:javascript
复制
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中而不是?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-11 21:26:54

因此,在回顾了媒体上的几个博客之后,我注意到了一些事情。

  1. 在我的tsconfig.js里,这个丢失了:

/*高级选项/ "forceConsistentCasingInFileNames":真/不允许不一致*/

因此,我手动添加了它,其次,我注意到了一些我想要删除的东西,但是忘记了。所以,不是这样的:

代码语言:javascript
复制
{
  "name": "@dc_microurb/common",
  "version": "1.0.5",
  "description": "",
  "main": "./build/index.js",
  "types": "./build/index.d.ts",
  "files": [
    "./build/**/*"
  ],

我需要这样做:

代码语言:javascript
复制
{
  "name": "@dc_microurb/common",
  "version": "1.0.6",
  "description": "",
  "main": "./build/index.js",
  "types": "./build/index.d.ts",
  "files": [
    "build/**/*"
  ],

在做了这些修正之后,现在我的包可以用于我的auth服务了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64793159

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档