Cannot destructure property ‘client’ of ‘db.config.connection’ as it is undefined

Cannot destructure property ‘client’ of ‘db.config.connection’ as it is undefined..can anyone show me where i got wrong..thanks…

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>config/database.ts
import path from 'path';
import { fileURLToPath } from 'url';
// Derive __filename and __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import { DatabaseConfig } from '../src/types/strapi';
export default ({ env }: { env: (key: string, defaultValue?: any) => any }): DatabaseConfig => {
// Resolve the filename with environment variable or default value
const filename = path.join(
__dirname,
'..',
'..',
env('DATABASE_FILENAME', path.join('.tmp', 'data.db'))
);
// Debugging output
console.log('Resolved Filename Path:', filename);
console.log('DATABASE_CLIENT:', env('DATABASE_CLIENT', 'sqlite'));
// Database configuration
const config: DatabaseConfig = {
connection: {
client: env('DATABASE_CLIENT', 'sqlite'),
connection: {
filename: filename,
},
useNullAsDefault: true,
},
};
// Return the configuration object
return config;
};
</code>
<code>config/database.ts import path from 'path'; import { fileURLToPath } from 'url'; // Derive __filename and __dirname const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); import { DatabaseConfig } from '../src/types/strapi'; export default ({ env }: { env: (key: string, defaultValue?: any) => any }): DatabaseConfig => { // Resolve the filename with environment variable or default value const filename = path.join( __dirname, '..', '..', env('DATABASE_FILENAME', path.join('.tmp', 'data.db')) ); // Debugging output console.log('Resolved Filename Path:', filename); console.log('DATABASE_CLIENT:', env('DATABASE_CLIENT', 'sqlite')); // Database configuration const config: DatabaseConfig = { connection: { client: env('DATABASE_CLIENT', 'sqlite'), connection: { filename: filename, }, useNullAsDefault: true, }, }; // Return the configuration object return config; }; </code>
config/database.ts

import path from 'path';
import { fileURLToPath } from 'url';

// Derive __filename and __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import { DatabaseConfig } from '../src/types/strapi'; 

export default ({ env }: { env: (key: string, defaultValue?: any) => any }): DatabaseConfig => {
  // Resolve the filename with environment variable or default value
  const filename = path.join(
    __dirname,
    '..',
    '..',
    env('DATABASE_FILENAME', path.join('.tmp', 'data.db'))
  );

  // Debugging output
  console.log('Resolved Filename Path:', filename); 
  console.log('DATABASE_CLIENT:', env('DATABASE_CLIENT', 'sqlite')); 

  // Database configuration
  const config: DatabaseConfig = {
    connection: {
      client: env('DATABASE_CLIENT', 'sqlite'), 
      connection: {
        filename: filename, 
      },
      useNullAsDefault: true, 

    },
  };

  // Return the configuration object
  return config;
};

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>src/types/strapi.d.ts
export interface DatabaseConfig {
connection: {
client: string;
connection: {
filename?: string;
host?: string;
port?: number;
database?: string;
user?: string;
password?: string;
};
useNullAsDefault?: boolean;
};
}
</code>
<code>src/types/strapi.d.ts export interface DatabaseConfig { connection: { client: string; connection: { filename?: string; host?: string; port?: number; database?: string; user?: string; password?: string; }; useNullAsDefault?: boolean; }; } </code>
src/types/strapi.d.ts
export interface DatabaseConfig {
  connection: {
    client: string;
    connection: {
      filename?: string;
      host?: string;
      port?: number;
      database?: string;
      user?: string;
      password?: string;
    };
    useNullAsDefault?: boolean;
  };
}

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>tscongfig.json
{
"extends": "@strapi/typescript-utils/tsconfigs/server",
"compilerOptions": {
"typeRoots": ["./node_modules/@types", "./src/types"],
"target": "ES2021",
"module": "node16",
"moduleResolution": "Node16",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"rootDir": "./src",
"outDir": "./build",
"skipLibCheck": true,
"strict": false,
"allowJs": true,
"checkJs": false,
"resolveJsonModule": true ,
"types":["node"] // Allow importing JSON modules
},
"include": ["src/**/*.ts"], // Include all .ts files in src
"exclude": ["node_modules", "build", ".cache", ".tmp"]
}
</code>
<code>tscongfig.json { "extends": "@strapi/typescript-utils/tsconfigs/server", "compilerOptions": { "typeRoots": ["./node_modules/@types", "./src/types"], "target": "ES2021", "module": "node16", "moduleResolution": "Node16", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "rootDir": "./src", "outDir": "./build", "skipLibCheck": true, "strict": false, "allowJs": true, "checkJs": false, "resolveJsonModule": true , "types":["node"] // Allow importing JSON modules }, "include": ["src/**/*.ts"], // Include all .ts files in src "exclude": ["node_modules", "build", ".cache", ".tmp"] } </code>
tscongfig.json

{
  "extends": "@strapi/typescript-utils/tsconfigs/server",
  "compilerOptions": {
    "typeRoots": ["./node_modules/@types", "./src/types"],
    "target": "ES2021",           
    "module": "node16",           
    "moduleResolution": "Node16",   
    "esModuleInterop": true,        
    "forceConsistentCasingInFileNames": true,
    "rootDir": "./src",             
    "outDir": "./build",          
    "skipLibCheck": true,           
    "strict": false,                
    "allowJs": true,               
    "checkJs": false,               
    "resolveJsonModule": true ,
    "types":["node"]      // Allow importing JSON modules
  },
  "include": ["src/**/*.ts"],       // Include all .ts files in src
  "exclude": ["node_modules", "build", ".cache", ".tmp"]
}

.env file
DATABASE_CLIENT=sqlite
DATABASE_FILENAME=.tmp/data.db

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package.json
{
"name": "strapi-backend",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"build": "tsc && strapi build",
"develop": "tsc && strapi develop",
"start": "strapi start"
},
"devDependencies": {
"@types/koa": "^2.15.0",
"@types/node": "^22.5.5",
"strapi-to-typescript": "^2.0.15",
"typescript": "^5.6.2"
},
"dependencies": {
"@strapi/plugin-cloud": "4.25.11",
"@strapi/plugin-i18n": "4.25.11",
"@strapi/plugin-users-permissions": "4.25.11",
"@strapi/strapi": "4.25.11",
"better-sqlite3": "8.6.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^5.3.4",
"sqlite3": "^5.1.7",
"styled-components": "^5.3.11"
},
"author": {
"name": "A Strapi developer"
},
"strapi": {
"uuid": "1165bdd3-f9da-4cad-88bb-00136497d786"
},
"engines": {
"node": ">=18.0.0 <=20.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}
</code>
<code>package.json { "name": "strapi-backend", "private": true, "version": "0.1.0", "description": "A Strapi application", "scripts": { "build": "tsc && strapi build", "develop": "tsc && strapi develop", "start": "strapi start" }, "devDependencies": { "@types/koa": "^2.15.0", "@types/node": "^22.5.5", "strapi-to-typescript": "^2.0.15", "typescript": "^5.6.2" }, "dependencies": { "@strapi/plugin-cloud": "4.25.11", "@strapi/plugin-i18n": "4.25.11", "@strapi/plugin-users-permissions": "4.25.11", "@strapi/strapi": "4.25.11", "better-sqlite3": "8.6.0", "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^5.3.4", "sqlite3": "^5.1.7", "styled-components": "^5.3.11" }, "author": { "name": "A Strapi developer" }, "strapi": { "uuid": "1165bdd3-f9da-4cad-88bb-00136497d786" }, "engines": { "node": ">=18.0.0 <=20.x.x", "npm": ">=6.0.0" }, "license": "MIT" } </code>
package.json
{
  "name": "strapi-backend",
  "private": true,
  "version": "0.1.0",
  "description": "A Strapi application",
  "scripts": {
    "build": "tsc && strapi build",
    "develop": "tsc && strapi develop",
    "start": "strapi start"
  },
  "devDependencies": {
    "@types/koa": "^2.15.0",
    "@types/node": "^22.5.5",
    "strapi-to-typescript": "^2.0.15",
    "typescript": "^5.6.2"
  },
  "dependencies": {
    "@strapi/plugin-cloud": "4.25.11",
    "@strapi/plugin-i18n": "4.25.11",
    "@strapi/plugin-users-permissions": "4.25.11",
    "@strapi/strapi": "4.25.11",
    "better-sqlite3": "8.6.0",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "react-router-dom": "^5.3.4",
    "sqlite3": "^5.1.7",
    "styled-components": "^5.3.11"
  },
  "author": {
    "name": "A Strapi developer"
  },
  "strapi": {
    "uuid": "1165bdd3-f9da-4cad-88bb-00136497d786"
  },
  "engines": {
    "node": ">=18.0.0 <=20.x.x",
    "npm": ">=6.0.0"
  },
  "license": "MIT"
}

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>//src/api/user/controller/user.ts
import { DatabaseConfig } from '../../../../src/types/strapi';
const dbConfig = strapi.config.get('database.connection') as DatabaseConfig['connection'];
if (dbConfig) {
console.log(dbConfig.client);
console.log(dbConfig.connection.filename);
} else {
console.error('Database configuration is missing or incorrect.');
}</code>
<code>//src/api/user/controller/user.ts import { DatabaseConfig } from '../../../../src/types/strapi'; const dbConfig = strapi.config.get('database.connection') as DatabaseConfig['connection']; if (dbConfig) { console.log(dbConfig.client); console.log(dbConfig.connection.filename); } else { console.error('Database configuration is missing or incorrect.'); }</code>
//src/api/user/controller/user.ts

import { DatabaseConfig } from '../../../../src/types/strapi';


const dbConfig = strapi.config.get('database.connection') as DatabaseConfig['connection'];

if (dbConfig) {
  console.log(dbConfig.client);
  console.log(dbConfig.connection.filename);
} else {
  console.error('Database configuration is missing or incorrect.');
}

i am developing a strapi application..can anyone show where i got wrong

TypeError: Cannot destructure property ‘client’ of ‘db.config.connection’ as it is undefined.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật