cnpm/cnpmjs.org

cnpm install报错

Closed this issue · 6 comments

`'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: false,
    numCPUs: os.cpus().length,

/*

  • server configure
    */

registryPort: 7001,
webPort: 7002,
bindingHost: '0.0.0.0', // 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: '100mb',
// 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
fengmk2: 'fengmk2@gmail.com',
admin: 'admin@cnpmjs.org',
dead_horse: 'dead_horse@qq.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: 'https://os.alipayobjects.com/rmsportal/oygxuIUkkrRccUz.jpg', // 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: 'cnpmjs',
username: 'root',
password: 'password',

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

// 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: 'r.cnpmjs.org',

/**

  • 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: [ '@cnpm', '@cnpmtest', '@cnpm-test' ],

// 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: 'exist', // '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',

// #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);
};
`
上面是我的配置文件,本地安装了cnpm。但是cnpm install报错,不管是windows,还是Linux上运行一段时间都报错。
image

但是在该文件夹下直接用taobao的源,npm install不报错。
把同步模式syncModel改成none,走代理会卡主。改成exist会报错,找不到包。
image
我怀疑是node版本问题,但是我node,换成14,12,9,8都不行。cnpm和npm也试过了,还是报错。源头地址也改过。

我的需求是在离线环境内网搭建一个cnpm使用,一开始的方法是拷贝node_modules到内网,写了个Python脚本,根据package.json依次npm publish,处理了几种异常,但是publish的相关依赖有问题。也无法使用。
现在的想法是在外网cnpm install ,让nfs下同步上我想要的所有tgz包,再拷贝tgz包到内网文件夹下,把数据库sql导出,放在内网环境数据库执行。但是通过自己搭建的cnpm 进行install一直报各种错误。本地无法获取包。
我cnpm代码是20201201时下的,release3.0.0也试过,数据库没问题。
请问怎么解决,快绝望了。。。。。。

你不要贴出来全部的配置项,
下面是我的配置, 我是用npm install cnpmjs.org 安装的2.19.4

{
    "debug": false,
    "enableCluster": true,
    "database":
    {
        "dialect": "mysql",
        "db": "cnpmjs",
        "username": "cnpmjs",
        "password": "xxxxxx",
        "host": "127.0.0.1,
        "pool":
        {
            "max": 50,
            "min": 0,
            "idle": 20000,
            "acquire": 20000
        },
        "timezone": "+08:00"
    },
    "enablePrivate": true,
    "admins":
    {
        "xxxx": "xxxxx@xxx.com"
    },
    "syncModel": "none",   // 私有库里存自己的代码, 其他全部代理到公网的
    "scopes": [ 
        "@xxxx"
    ],
    "sourceNpmRegistry": "https://registry.npm.taobao.org",
    "registryPort": 7001,
  	"webPort": 7002,
  	"registryHost": "registry.npm.xxxxx.com", // 一定要配置这个,才可以正常使用
}

已经可以正常的npm publish , npm install 了

是不是3.0.0-rc版本的cnpmjs.org还有问题?我用的3.0.0-rc.39,nodejs是12.9.0,也是安装一个库中没有的包,会报错

@Superman-wc ,您好,想请教下,我这边安装好了cnpm,但是npm login的时候需要输入密码呢。这cnpm初始admin的密码是啥,文档中也没看到有说呀。就看到一个admin和email

@

@Superman-wc ,你好,想教下,我这个安装好了cnpm,但是npm 登录的时候需要输入密码。这cnpm 最终管理员的密码是啥,文档中没有看到说呀。查看一个管理员和电子邮件

第一次登陆即为注册,密码随便输,下次使用该用户的时候也要使用第一登录时密码