安装自定义软件包失败

问题描述 投票:0回答:1

我正在创建一个 CLI 包。我正在发布到 GitHub 帐户,并且我有

.npmrc
指向
@myorg:registry=https://npm.pkg.github.com
。我可以使用
npm pack <package>
看到已发布包的内容,但是当我尝试
npm install <package>
时,操作失败,因为找不到
package.json
。这是因为
node_modules
中没有创建包文件夹。

我运行了

npm install --verbose <package>
,所有请求似乎在错误发生之前都成功了。

这是我创建的第二个包,第一个包工作得很好。

为什么可能无法创建包文件夹?

这就是我的

package.json
在发布的包中的样子。

{
  "name": "@myorg/cy-membership-test-client",
  "bin": {
    "cy-membership-test-client": "./lib/index.js"
  },
  "scripts": {
    "build": "tsc",
    "start": "ts-node ./src/index.ts",
    "patch-release": "npm version patch && npm publish && git push --follow-tags"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/myorg/cy-membership-test-client.git"
  },
  "publishConfig": {
    "registry": "https://npm.pkg.github.com"
  },
  "owner": "myorg",
  "author": "Josh Russo",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/myorg/cy-membership-test-client/issues"
  },
  "homepage": "https://github.com/myorg/cy-membership-test-client#readme",
  "dependencies": {
    "@myorg/cy-membership-api-client": "^1.0.104",
    "@myorg/cy-membership-test-client": "file:",
    "command-line-args": "^6.0.0",
    "cy-membership-test-client": "file:",
    "dotenv": "^16.4.5",
    "ts-node": "^10.9.2"
  },
  "devDependencies": {
    "@types/node": "^22.3.0"
  },
  "version": "0.0.3"
}

这就是详细输出的样子。

npm verb cli C:\Program Files\nodejs\node.exe C:\Users\jrusso\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
npm info using [email protected]
npm info using [email protected]
npm verb title npm install @myorg/cy-membership-test-client
npm verb argv "install" "--loglevel" "verbose" "@myorg/cy-membership-test-client"
npm verb logfile logs-max:10 dir:C:\Users\jrusso\AppData\Local\npm-cache\_logs\2024-09-16T19_08_22_238Z-
npm verb logfile C:\Users\jrusso\AppData\Local\npm-cache\_logs\2024-09-16T19_08_22_238Z-debug-0.log
npm verb shrinkwrap failed to load node_modules/.package-lock.json missing from node_modules: node_modules/membership-test-client-install-test
npm http fetch GET 200 https://npm.pkg.github.com/@myorg%2fcy-membership-test-client 456ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/ts-node 165ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/command-line-args 217ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@swc%2fcore 111ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@swc%2fhelpers 90ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@swc%2fwasm 100ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@types%2fnode 83ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/typescript 77ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/typical 112ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/array-back 118ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/undici-types 151ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/find-replace 181ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/arg 181ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/create-require 187ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@cspotcode%2fsource-map-support 199ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@tsconfig%2fnode16 214ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/make-error 241ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/v8-compile-cache-lib 240ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@tsconfig%2fnode14 244ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/acorn 248ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/lodash.camelcase 271ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/acorn-walk 271ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/diff 273ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/yn 284ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@tsconfig%2fnode10 313ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@tsconfig%2fnode12 329ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@jridgewell%2ftrace-mapping 100ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@jridgewell%2fresolve-uri 113ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/@jridgewell%2fsourcemap-codec 118ms (cache revalidated)
npm verb stack Error: ENOENT: no such file or directory, open 'C:\temp\my-org\membership-test-client-install-test\node_modules\@myorg\cy-membership-test-client\package.json'
npm verb cwd C:\temp\my-org\membership-test-client-install-test
npm verb Windows_NT 10.0.22621
npm verb node v20.10.0
npm verb npm  v9.2.0
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\temp\my-org\membership-test-client-install-test\node_modules\@myorg\cy-membership-test-client/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\temp\my-org\membership-test-client-install-test\node_modules\@myorg\cy-membership-test-client\package.json'    
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm verb exit -4058
npm verb unfinished npm timer reify 1726513702302
npm verb unfinished npm timer reify:loadTrees 1726513702303
npm verb code -4058

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\jrusso\AppData\Local\npm-cache\_logs\2024-09-16T19_08_22_238Z-debug-0.log

这就是

npm pack
输出的样子。

npm notice
npm notice 📦  @myorg/[email protected]
npm notice === Tarball Contents ===
npm notice 0B     .env
npm notice 23B    build.ps1
npm notice 2.8kB  lib/index.js
npm notice 77B    lib/messageTest.js
npm notice 6.2kB  lib/userTests.js
npm notice 725B   package.json
npm notice 80B    run.ps1
npm notice 1.6kB  src/index.ts
npm notice 193B   src/messageTest.ts
npm notice 5.0kB  src/userTests.ts
npm notice 12.3kB tsconfig.json
npm notice === Tarball Details ===
npm notice name:          @myorg/cy-membership-test-client
npm notice version:       0.0.4
npm notice filename:      myorg-cy-membership-test-client-0.0.4.tgz
npm notice package size:  7.3 kB
npm notice unpacked size: 29.0 kB
npm notice shasum:        2ef3f1a94b93c8ca347433cc317d3c6dd3ba97e7
npm notice integrity:     sha512-wbq6+NtXgZVfK[...]XCDQIWjy5N6mA==
npm notice total files:   11
npm notice
myorg-cy-membership-test-client-0.0.4.tgz
npm
1个回答
0
投票

在您尝试安装的项目中,确保您有一个

package.json
; 如果您有
package-lock.json
,请将其删除并重试。

© www.soinside.com 2019 - 2024. All rights reserved.