简体   繁体   English

使用 verdaccio 未按预期安装发布的 npm 包

[英]published npm package not installed as expected using verdaccio

my objective is to build and publish a package for commonly used typescript functions on verdaccio, an npm registry running on docker.我的目标是在 verdaccio(一个在 docker 上运行的 npm 注册表)上构建和发布一个常用的 typescript 函数包。

I build my typescript package.我构建了我的打字稿包。 this is my project structure这是我的项目结构

在此处输入图像描述

package.json包.json

    {
  "name": "communications",
  "version": "1.0.0",
  "description": "provides functional way of interacting with NATS",
  "main": "lib/index.js",
  "types": "lib/index.d.ts",
  "files": [
    "lib/**/*"
  ],
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "tsc",
    "library": "tsc && npm unpublish --force --registry http://localhost:4873 && npm publish --registry http://localhost:4873"
  },
  "author": "bumblebee",
  "license": "ISC",
  "dependencies": {
    "nats": "^2.9.2"
  }
}

this is my tsconfig.json这是我的 tsconfig.json

{
  "compilerOptions": {
    /* Language and Environment */
    "target": "ES2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,

    /* Modules */
    "module": "CommonJS" /* Specify what module code is generated. */,
    /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

    /* JavaScript Support */
    // "allowJs": true,                                  /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
    // "checkJs": true,                                  /* Enable error reporting in type-checked JavaScript files. */
    // "maxNodeModuleJsDepth": 1,                        /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */

    /* Emit */
    "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
    "declarationMap": true /* Create sourcemaps for d.ts files. */,
    "outDir": "./lib" /* Specify an output folder for all emitted files. */,

    /* Interop Constraints */
    "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
    "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

    /* Type Checking */
    "strict": true /* Enable all strict type-checking options. */,
    "noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
    "strictNullChecks": true /* When type checking, take into account 'null' and 'undefined'. */,
    "strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
    "strictBindCallApply": true /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */,
    "strictPropertyInitialization": true /* Check for class properties that are declared but not set in the constructor. */,
    "noImplicitThis": true /* Enable error reporting when 'this' is given the type 'any'. */,
    "alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
    "noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
    "noUnusedParameters": true /* Raise an error when a function parameter isn't read. */,
    "noUncheckedIndexedAccess": true /* Add 'undefined' to a type when accessed using an index. */,
    "noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,

    /* Completeness */
    "skipLibCheck": true /* Skip type checking all .d.ts files. */
  },
  "include": ["src"],
  "exclude": ["node_modules", "**/__tests__/*"]
}

this is my.npmignore这是我的.npmignore

package-lock.json
node_modules/

this is the folder structure in my lib after running tsc这是运行 tsc 后我的库中的文件夹结构

在此处输入图像描述

The project is successfully published in verdaccio.该项目已成功发布在 verdaccio 中。 when I try to install it using当我尝试使用安装它时

npm install communications --registry http://localhost:4873/ 

here is what I get这是我得到的

在此处输入图像描述

package.json is the only file I get. package.json 是我得到的唯一文件。 nothing else.没有其他的。 off course this results in compilation errors even for importing anything.当然,即使导入任何东西,这也会导致编译错误。

Why is it that my lib folder is completely ignored and not pubslied in the npm package?为什么我的 lib 文件夹被完全忽略并且没有发布在 npm 包中?

thats那是

Everything I was doing was correct.我所做的一切都是正确的。 I was not using the command我没有使用命令

npm pack

which creates a compressed package communication.nats-1.0.0.tgz that was also published.它创建了一个压缩包communication.nats-1.0.0.tgz也被发布了。 only after that I was able to get all the required files.只有在那之后我才能获得所有必需的文件。 It was a silly mistake but the article I followed didn't mention this at all.这是一个愚蠢的错误,但我关注的文章根本没有提到这一点。 the sequence should be as follows:顺序应如下:

tsc
npm pack
npm publish --registry="path-to-custom-registry:port"

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

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