通过npm overrides 解决cube.js oracle driver 依赖oracle 版本问题
以前我通过替换解决的(适合容器场景),以下是使用npm 自带的特性解决
项目配置
- package.json
如下,替换@cubejs-backend/oracle-driver 包以来的oracle 包为新安装的
{
"name": "demo-app",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "node index.js"
},
"template": "express",
"templateVersion": "0.34.5",
"dependencies": {
"@cubejs-backend/oracle-driver": "^0.34.1",
"@cubejs-backend/server": "^0.34.5",
"oracledb": "^6.2.0"
},
"overrides": {
"@cubejs-backend/oracle-driver":{
"oracledb":"^6.2.0"
}
}
}
- 项目使用
index.js 基于express 模版
const CubejsServer = require('@cubejs-backend/server');
const server = new CubejsServer({});
server.listen().then(({ version, port }) => {
console.log(`🚀 Cube server (${version}) is listening on ${port}`);
}).catch(e => {
console.error('Fatal error during server start: ');
console.error(e.stack || e);
});
.env
# Cube environment variables: https://cube.dev/docs/reference/environment-variables
CUBEJS_DEV_MODE=true
CUBEJS_DB_TYPE=oracle
CUBEJS_API_SECRET=cb3d5e39072c1d21b547341ada5b491af2bc9c8f6a5841ed9c2e0082573a8dfbcc68b5be6c4bbb8e83cc87e7bfe1dcb3bcf97d815959159ab80b8dd8eee64819
CUBEJS_EXTERNAL_DEFAULT=true
CUBEJS_SCHEDULED_REFRESH_DEFAULT=true
CUBEJS_SCHEMA_PATH=model
CUBEJS_WEB_SOCKETS=true
CUBEJS_DB_HOST=xxxx
CUBEJS_DB_NAME=xxxx
CUBEJS_DB_USER=xxxxx
CUBEJS_DB_PASS=xxxx
- 效果
说明
npm overrides 是一个方便的功能,但是在使用的时候注意可能需要删除node_modules 以及package-lock.json 这样才能保证以来可以替换成功
参考资料
https://github.com/npm/cli/issues/4232
https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides
https://stackoverflow.com/questions/70939926/overriding-npm-dependency-of-a-dependency-in-package-json