Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

发布包后安装失败提示 Not Found #1605

Closed
johnnhan opened this issue Dec 9, 2020 · 4 comments
Closed

发布包后安装失败提示 Not Found #1605

johnnhan opened this issue Dec 9, 2020 · 4 comments

Comments

@johnnhan
Copy link

johnnhan commented Dec 9, 2020

在公司内网搭了一套 CNPM,已经能正常发布包了,直接访问 http://172.22.14.43:7001/@ebfed/webpack-alioss-acl-plugin/-/@ebfed/webpack-alioss-acl-plugin-0.1.1.tgz 也能下载文件,但是,通过 npm i 的方式安装的时候,却提示 Not Found

npm ERR! code E404
npm ERR! 404 Not Found - GET https://cnpmjs.oss-ap-southeast-1.aliyuncs.com/%40ebfed/webpack-alioss-acl-plugin/-/%40ebfed/webpack-alioss-acl-plugin-0.1.1.tgz

这也让我产生了一个疑问,为什么 npm i 的时候走的 https://cnpmjs.oss-ap-southeast-1.aliyuncs.com/,而不是 http://172.22.14.43:7001/

我的配置文件如下

'use strict';

var mkdirp = require('mkdirp');
var copy = require('copy-to');
var path = require('path');
var fs = require('fs');
var os = require('os');
var utility = require('utility');

var version = require('../package.json').version;

var root = path.dirname(__dirname);
var dataDir = path.join(process.env.HOME || root, '.cnpmjs.org');

var config = {
  version: version,
  dataDir: dataDir,

  /**
   * Cluster mode
   */
  enableCluster: true,
  numCPUs: os.cpus().length,

  /*
   * server configure
   */

  registryPort: 7001,
  webPort: 7002,
  bindingHost: '127.0.0.1', // only binding on 127.0.0.1 for local access
  // default is ctx.protocol
  protocol: '',

  // debug mode
  // if in debug mode, some middleware like limit wont load
  // logger module will print to stdout
  debug: process.env.NODE_ENV === 'development',
  // page mode, enable on development env
  pagemock: process.env.NODE_ENV === 'development',
  // session secret
  sessionSecret: 'cnpmjs.org test session secret',
  // max request json body size
  jsonLimit: '10mb',
  // log dir name
  logdir: path.join(dataDir, 'logs'),
  // update file template dir
  uploadDir: path.join(dataDir, 'downloads'),
  // web page viewCache
  viewCache: false,

  // registry http response cache control header
  // if you are using CDN, can set it to 'max-age=0, s-maxage=10, must-revalidate'
  // it meaning cache 10s on CDN server and no cache on client side.
  registryCacheControlHeader: '',
  // if you are using CDN, can set it to 'Accept, Accept-Encoding'
  registryVaryHeader: '',
  // disable package search
  disableSearch: false,

  // view files directory
  viewDir: path.join(root, 'view', 'web'),

  customRegistryMiddlewares: [],
  customWebMiddlewares: [],

  // config for koa-limit middleware
  // for limit download rates
  limit: {
    enable: false,
    token: 'koa-limit:download',
    limit: 1000,
    interval: 1000 * 60 * 60 * 24,
    whiteList: [],
    blackList: [],
    message: 'request frequency limited, any question, please contact fengmk2@gmail.com',
  },

  enableCompress: false, // enable gzip response or not

  // default system admins
  admins: {
    // name: email
    admin: 'admin@xx.com',
  },

  // email notification for errors
  // check https://github.com/andris9/Nodemailer for more informations
  mail: {
    enable: false,
    appname: 'cnpmjs.org',
    from: 'cnpmjs.org mail sender <adderss@gmail.com>',
    service: 'gmail',
    auth: {
      user: 'address@gmail.com',
      pass: 'your password'
    }
  },

  logoURL: '/logo.png', // cnpm logo image url
  adBanner: '',
  customReadmeFile: '', // you can use your custom readme file instead the cnpm one
  customFooter: '', // you can add copyright and site total script html here
  npmClientName: 'cnpm', // use `${name} install package`
  packagePageContributorSearch: true, // package page contributor link to search, default is true

  // max handle number of package.json `dependencies` property
  maxDependencies: 200,
  // backup filepath prefix
  backupFilePrefix: '/cnpm/backup/',

  /**
   * database config
   */

  database: {
    db: 'eb_npm',
    username: 'ebnpm',
    password: 'xxxxxx',

    // the sql dialect of the database
    // - currently supported: 'mysql', 'sqlite', 'postgres', 'mariadb'
    dialect: 'mariadb',

    // custom host; default: 127.0.0.1
    host: '127.0.0.1',

    // custom port; default: 3306
    port: 3306,

    // use pooling in order to reduce db connection overload and to increase speed
    // currently only for mysql and postgresql (since v1.5.0)
    pool: {
      maxConnections: 10,
      minConnections: 0,
      maxIdleTime: 30000
    },

    dialectOptions: {
      // if your server run on full cpu load, please set trace to false
      trace: true,
    },

    // the storage engine for 'sqlite'
    // default store into ~/.cnpmjs.org/data.sqlite
    storage: path.join(dataDir, 'data.sqlite'),

    logging: !!process.env.SQL_DEBUG,
  },

  // enable proxy npm audits request or not
  enableNpmAuditsProxy: true,

  // package tarball store in local filesystem by default
  nfs: require('fs-cnpm')({
    dir: path.join(dataDir, 'nfs')
  }),
  // if set true, will 302 redirect to `nfs.url(dist.key)`
  downloadRedirectToNFS: false,
  // don't check database and just download tgz from nfs
  downloadTgzDontCheckModule: false,
  // remove original tarball when publishing
  unpublishRemoveTarball: true,

  // registry url name
  registryHost: '127.0.0.1:7001',

  /**
   * registry mode config
   */

  // enable private mode or not
  // private mode: only admins can publish, other users just can sync package from source npm
  // public mode: all users can publish
  enablePrivate: false,

  // registry scopes, if don't set, means do not support scopes
  scopes: [ '@ebfed' ],

  // some registry already have some private packages in global scope
  // but we want to treat them as scoped private packages,
  // so you can use this white list.
  privatePackages: [],

  /**
   * sync configs
   */

  // the official npm registry
  // cnpm wont directly sync from this one
  // but sometimes will request it for some package infomations
  // please don't change it if not necessary
  officialNpmRegistry: 'https://registry.npmjs.com',
  officialNpmReplicate: 'https://replicate.npmjs.com',
  cnpmRegistry: 'https://r.cnpmjs.com',

  // sync source, upstream registry
  // If you want to directly sync from official npm's registry
  // please drop them an email first
  sourceNpmRegistry: 'https://registry.npm.taobao.org',
  sourceNpmWeb: 'https://npm.taobao.org',

  // upstream registry is base on cnpm/cnpmjs.org or not
  // if your upstream is official npm registry, please turn it off
  sourceNpmRegistryIsCNpm: true,

  // if install return 404, try to sync from source registry
  syncByInstall: true,

  // sync mode select
  // none: do not sync any module, proxy all public modules from sourceNpmRegistry
  // exist: only sync exist modules
  // all: sync all modules
  syncModel: 'none', // 'none', 'all', 'exist'

  syncConcurrency: 1,
  // sync interval, default is 10 minutes
  syncInterval: '10m',

  // sync polular modules, default to false
  // because cnpm can't auto sync tag change for now
  // so we want to sync popular modules to ensure their tags
  syncPopular: false,
  syncPopularInterval: '1h',
  // top 100
  topPopular: 100,

  // sync devDependencies or not, default is false
  syncDevDependencies: false,
  // try to remove all deleted versions from original registry
  syncDeletedVersions: true,

  // changes streaming sync
  syncChangesStream: false,
  syncDownloadOptions: {
    // formatRedirectUrl: function (url, location)
  },
  handleSyncRegistry: 'http://127.0.0.1:7001',

  // default badge subject
  badgeSubject: 'cnpm',
  // defautl use https://badgen.net/
  badgeService: {
    url: function(subject, status, options) {
      options = options || {};
      let url = `https://badgen.net/badge/${utility.encodeURIComponent(subject)}/${utility.encodeURIComponent(status)}`;
      if (options.color) {
        url += `/${utility.encodeURIComponent(options.color)}`;
      }
      if (options.icon) {
        url += `?icon=${utility.encodeURIComponent(options.icon)}`;
      }
      return url;
    },
  },

  packagephobiaURL: 'https://packagephobia.now.sh',
  packagephobiaSupportPrivatePackage: false,
  packagephobiaMinDownloadCount: 1000,

  // custom user service, @see https://github.com/cnpm/cnpmjs.org/wiki/Use-Your-Own-User-Authorization
  // when you not intend to ingegrate with your company's user system, then use null, it would
  // use the default cnpm user system
  userService: null,

  // always-auth https://docs.npmjs.com/misc/config#always-auth
  // Force npm to always require authentication when accessing the registry, even for GET requests.
  alwaysAuth: false,

  // if you're behind firewall, need to request through http proxy, please set this
  // e.g.: `httpProxy: 'http://proxy.mycompany.com:8080'`
  httpProxy: null,

  // snyk.io root url
  snykUrl: 'https://snyk.io',

  // https://github.com/cnpm/cnpmjs.org/issues/1149
  // if enable this option, must create module_abbreviated and package_readme table in database
  enableAbbreviatedMetadata: false,

  // global hook function: function* (envelope) {}
  // envelope format please see https://github.com/npm/registry/blob/master/docs/hooks/hooks-payload.md#payload
  globalHook: null,

  opensearch: {
    host: '',
  },

  // redis cache
  redisCache: {
    enable: false,
    connectOptions: null,
  },
};

if (process.env.NODE_ENV === 'test') {
  config.enableAbbreviatedMetadata = true;
  config.customRegistryMiddlewares.push(() => {
    return function* (next) {
      this.set('x-custom-middleware', 'true');
      yield next;
    };
  });

  config.customWebMiddlewares.push(() => {
    return function* (next) {
      this.set('x-custom-web-middleware', 'true');
      yield next;
    };
  });
}

if (process.env.NODE_ENV !== 'test') {
  var customConfig;
  if (process.env.NODE_ENV === 'development') {
    customConfig = path.join(root, 'config', 'config.js');
  } else {
    // 1. try to load `$dataDir/config.json` first, not exists then goto 2.
    // 2. load config/config.js, everything in config.js will cover the same key in index.js
    customConfig = path.join(dataDir, 'config.json');
    if (!fs.existsSync(customConfig)) {
      customConfig = path.join(root, 'config', 'config.js');
    }
  }
  if (fs.existsSync(customConfig)) {
    copy(require(customConfig)).override(config);
  }
}

mkdirp.sync(config.logdir);
mkdirp.sync(config.uploadDir);

module.exports = config;

config.loadConfig = function (customConfig) {
  if (!customConfig) {
    return;
  }
  copy(customConfig).override(config);
};
@Superman-wc
Copy link

我也遇到了同样的问题
npm ERR! 404 Not Found - GET https://cnpmjs.oss-ap-southeast-1.aliyuncs.com/%40bugu/utils/-/%40bugu/utils-0.0.4.tgz

@Superman-wc
Copy link

已经找到解决方法了, 我安装的是2.19.4的版本, npm install 安装的,
注意config里设置一下registryHost这个配置成你自己的registry就可以了, 默认是r.cnpmjs.org,
自己搭的时候要设置registryHost才能正常工作

@johnnhan
Copy link
Author

johnnhan commented Dec 14, 2020

@Superman-wc

已经找到解决方法了, 我安装的是2.19.4的版本, npm install 安装的,
注意config里设置一下registryHost这个配置成你自己的registry就可以了, 默认是r.cnpmjs.org,
自己搭的时候要设置registryHost才能正常工作

多谢解答,我后面也定位到那个配置了,发布包的时候,会把 registryHost 作为前缀写入数据库,后面 npm i 的时候会根据数据库中存放的地址去下载相应包

{
	"_id": "@ebfed/webpack-alioss-acl-plugin",
	"_rev": "8",
	"name": "@ebfed/webpack-alioss-acl-plugin",
	"description": "Ali oss-webpack auto upload files plugin with acl options",
	"dist-tags": {
		"latest": "0.1.1"
	},
	"maintainers": [{
		"name": "xx",
		"email": "xx@xx.com"
	}],
	"time": {
		"modified": "2020-12-09T08:06:14.000Z",
		"created": "2020-12-09T08:06:14.192Z",
		"0.1.1": "2020-12-09T08:06:14.192Z"
	},
	"users": {},
	"author": {
		"name": "Johnhan"
	},
	"repository": {
		"type": "git",
		"url": "git+https://github.com/johnnhan/webpack-alioss-acl-plugin.git"
	},
	"versions": {
		"0.1.1": {
			"name": "@ebfed/webpack-alioss-acl-plugin",
			"version": "0.1.1",
			"description": "Ali oss-webpack auto upload files plugin with acl options",
			"homepage": "http://www.johnhan.cn/",
			"repository": {
				"type": "git",
				"url": "git+https://github.com/johnnhan/webpack-alioss-acl-plugin.git"
			},
			"license": "MIT",
			"author": {
				"name": "Johnhan"
			},
			"keywords": ["webpack", "oss", "aliyun"],
			"main": "lib/index.js",
			"scripts": {
				"build": "babel src --out-dir lib"
			},
			"dependencies": {
				"ali-oss": "^6.1.0",
				"babel-runtime": "^6.26.0",
				"chalk": "^2.4.2",
				"lodash": "^4.17.11"
			},
			"devDependencies": {
				"babel-cli": "^6.26.0",
				"babel-core": "^6.26.3",
				"babel-eslint": "^10.0.1",
				"babel-plugin-transform-runtime": "^6.23.0",
				"babel-preset-env": "^1.7.0",
				"babel-preset-stage-0": "^6.24.1"
			},
			"readmeFilename": "README.md",
			"gitHead": "6a4cc6de45051fdf68eee8b52e4fa95add1b1e46",
			"bugs": {
				"url": "https://github.com/johnnhan/webpack-alioss-acl-plugin/issues"
			},
			"_id": "@ebfed/webpack-alioss-acl-plugin@0.1.1",
			"_nodeVersion": "14.8.0",
			"_npmVersion": "6.14.7",
			"dist": {
				"shasum": "b2341b718210e45e4be8344937d20ad66135d2a4",
				"size": 6835,
				"key": "/@ebfed/webpack-alioss-acl-plugin/-/@ebfed/webpack-alioss-acl-plugin-0.1.1.tgz",
				"tarball": "http://127.0.0.1:7001/@ebfed/webpack-alioss-acl-plugin/download/@ebfed/webpack-alioss-acl-plugin-0.1.1.tgz"
			},
			"_publish_on_cnpm": true,
			"_cnpm_publish_time": 1607501174192,
			"publish_time": 1607501174192,
			"maintainers": [{
				"name": "xx",
				"email": "xx@xx.com"
			}]
		}
	},
	"readme": "# [webpack-alioss-acl-plugin](https://github.com/johnnhan/webpack-alioss-acl-plugin)\r\n\r\n![](https://img.shields.io/github/package-json/v/johnnhan/webpack-alioss-acl-plugin)\r\n![](https://img.shields.io/github/license/johnnhan/webpack-alioss-acl-plugin)\r\n\r\n插件基于开源项目 [webpack-alioss-plugin](https://github.com/borenXue/webpack-alioss-plugin),由于公司项目要求上传 OSS 后修改文件的权限,所以本插件在此基础上添加 ACL 的配置项,以及在 put 请求之后追加 putACL 请求\r\n\r\n## 安装\r\n\r\n```\r\nnpm install -D webpack-alioss-acl-plugin\r\n```\r\n\r\n## 使用示例 - vue.config.js 示例\r\n\r\n```js\r\nconst WebpackAliossPlugin = require('webpack-alioss-acl-plugin');\r\nconst isProduction = process.env.NODE_ENV === 'production';\r\n\r\nmodule.exports = {\r\n  publicPath: isProduction ? '//xx.com/auto_upload_ci/your-project-name/' : '',\r\n  configureWebpack: {\r\n    plugins: isProduction ? [\r\n      new WebpackAliossPlugin({\r\n        auth: {\r\n          accessKeyId: '', // 在阿里 OSS 控制台获取\r\n          accessKeySecret: '', // 在阿里 OSS 控制台获取\r\n          region: 'oss-cn-hangzhou', // OSS 服务节点, 示例: oss-cn-hangzhou\r\n          bucket: 'abc', // OSS 存储空间, 在阿里 OSS 控制台获取\r\n        },\r\n        ossBaseDir: 'auto_upload_ci',\r\n        project: 'my-project-name', // 项目名(用于存放文件的直接目录)\r\n        acl: 'piblic-read', // 设置文件访问权限\r\n      }),\r\n    ] : [],\r\n  },\r\n};\r\n```\r\n\r\n## 参数说明\r\n\r\n| 构造参数 | 默认值 | 说明 |\r\n| --- | --- | --- |\r\n| acl | '' | 设置文件权限,可选 private/public-read/public-read-write,不传则保持默认权限 |\r\n\r\n其他参数同 [webpack-alioss-plugin](https://github.com/borenXue/webpack-alioss-plugin)\r\n",
	"_attachments": {},
	"readmeFilename": "README.md",
	"homepage": "http://www.johnhan.cn/",
	"bugs": {
		"url": "https://github.com/johnnhan/webpack-alioss-acl-plugin/issues"
	},
	"license": "MIT"
}

上面是写入到数据库中的内容,注意那个 tarball 字段对应的值,他的前缀就是拿的 registryHost

@Brolly0204
Copy link

@johnnhan 我本地改成 registryHost: '127.0.0.1:7001', 为啥还是报404 我的版本是3.0.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants