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

Check tsconfig and add .ts to imports #18

Closed
hilja opened this issue Jan 12, 2024 · 8 comments · Fixed by #28
Closed

Check tsconfig and add .ts to imports #18

hilja opened this issue Jan 12, 2024 · 8 comments · Fixed by #28

Comments

@hilja
Copy link

hilja commented Jan 12, 2024

Screenshot 2024-01-12 at 17 16 01

Not a big problem, but if you’ve got something like this in tsonfig you need to import with .ts extension. Could also be a setting.

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "target": "ES2022",
    "allowImportingTsExtensions": true,
  }
}
@hilja
Copy link
Author

hilja commented Jan 13, 2024

Ah, this won't work drizzle-team/drizzle-orm#849 I ran the generator yesterday evening and didn't try to migrate until this morning and noticed it can't find the tables.

@hilja
Copy link
Author

hilja commented Jan 13, 2024

This is the way:

"scripts": {
  "generate": "NODE_OPTIONS='--import tsx' drizzle-kit generate:pg"
}

A bit off-topic but, is the following supposed to work?

export default defineConfig({
  schema: './drizzle/schema/schema.ts',
})

It can't find any tables from the schema.ts, but glob works fine :)

export default defineConfig({
  schema: './drizzle/schema/*',
})

@fdarian
Copy link
Owner

fdarian commented Jan 14, 2024

@hilja do you mind making a repository where I can reproduce the issue?

So far I'm importing the generated models in a next.js project (using the tsconfig created from create-next-app) and a simple ts project works fine

@hilja
Copy link
Author

hilja commented Jan 14, 2024

Here's a quick repro:

The app I was testing with is loosely based on the epic stack https://github.com/epicweb-dev/epic-stack

So I hacked up prisma-generator-drizzle in there https://github.com/hilja/drizzle-test. Note that the app won't actually work because I used postgres (epic-stack is sqlite). But the generator should.

Setup:

git clone git@github.com:hilja/drizzle-test.git
cd drizzle-test
npm i
npm prisma generate

After generating the drizzle schema, the imports in prisma/drizzle/schema should error: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Adding .ts or .js manually fixes it.

And when trying to drizzle-kit generate:pg with npm run generate, it can’t find any tables:

0 tables

No schema changes, nothing to migrate 😴

@fdarian fdarian mentioned this issue Jan 20, 2024
Open
19 tasks
@daniel-nagy
Copy link
Contributor

I have the same issue. To make things easy I believe this library could just always add the .js extension to the import path. I believe that would work in all cases but I could be wrong.

@daniel-nagy
Copy link
Contributor

I just opened a PR to add the js extension. @hilja as a temporary workaround you can use my fork by installing it from a git URL.

yarn add daniel-nagy/prisma-generator-drizzle#js-ext-pkg

@fdarian
Copy link
Owner

fdarian commented Jan 27, 2024

@daniel-nagy @hilja I just patched the import logic to determine based on the project's moduleResolution, let me know if it's not working

@fdarian
Copy link
Owner

fdarian commented Jan 27, 2024

@daniel-nagy @hilja I just patched the import logic to determine based on the project's moduleResolution, let me know if it's not working

It breaks on my repo 😅

I couldn't find any better approach, so I just provide the config to override

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

Successfully merging a pull request may close this issue.

3 participants