Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing file with alias path is not working #109

Open
JeromeDeLeon opened this issue Sep 17, 2024 · 2 comments
Open

Importing file with alias path is not working #109

JeromeDeLeon opened this issue Sep 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@JeromeDeLeon
Copy link

JeromeDeLeon commented Sep 17, 2024

Description

Currently, the kysely.config.ts file is importing the kysely instance I created on a separate file and the path is an alias path like @/path/to/kysely.

This throws an error on the CLI.

Looking at c12, it looks like it's exposing jitiOptions which also exposes the alias to allow alias path.

ERROR  Cannot find module '@/path/to/kysely'
Require stack:
- /repo/kysely.config.ts

  Require stack:
  - kysely.config.ts
  at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
  at Function.resolve (node:internal/modules/helpers:190:19)
  at _resolve (node_modules/jiti/dist/jiti.js:1:241814)
  at jiti (node_modules/jiti/dist/jiti.js:1:244531)
  at kysely.config.ts:2:15
  at evalModule (node_modules/jiti/dist/jiti.js:1:247313)
  at Object.jiti (node_modules/jiti/dist/jiti.js:1:245241)
  at resolveConfig (node_modules/c12/dist/shared/c12.cab0c9da.mjs:345:26)
  at loadConfig (node_modules/c12/dist/shared/c12.cab0c9da.mjs:147:29)
  at async getConfig (node_modules/kysely-ctl/dist/bin.js:226:24)

Workaround

Manually configure using dialect and dialectConfig essentially repeating the same logic.

Package Info

kysely v0.27.4
kysely-ctl v0.9.0
@JeromeDeLeon
Copy link
Author

Another workaround is to use jiti inside the config and move .env.local to .env for Next.js application

import { fileURLToPath } from 'url';
import createJiti from 'jiti';
import { defineConfig } from 'kysely-ctl';

const moduleFileUrl = import.meta.url;

const jiti = createJiti(fileURLToPath(moduleFileUrl), {
  // Since `jiti` uses isolated environment, we need to provide an alias for the src directory
  // See: https://github.com/unjs/jiti/issues/104
  alias: { '@': fileURLToPath(new URL('./src', moduleFileUrl)) },
});

const kysely = jiti('./src/path/to/kysely.ts');

export default defineConfig({
  kysely,
  // other kysely-ctl config
});

@gvanderclay
Copy link

I encountered the same issue. Luckily @JeromeDeLeon's workaround works!

@igalklebanov igalklebanov added the bug Something isn't working label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants