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

Cannot find module 'sqlocal/drizzle' or its corresponding type declarations.ts(2307) #1

Closed
reslear opened this issue Aug 6, 2023 · 15 comments

Comments

@reslear
Copy link

reslear commented Aug 6, 2023

Screenshot 2023-08-06 at 17 44 27

maybe need to migrate https://github.com/egoist/tsup to better generate js mjs d.ts

@DallasHoff
Copy link
Owner

Hi there! It would be helpful if you could describe in more detail what issue you are having and provide some information about your environment's setup. In this case, the most relevant information would probably be your package.json file and your TypeScript configuration.

Ideally, you could provide a minimal reproduction. As an example, I just put together a minimal "hello world" app for using SQLocal with Drizzle here: https://github.com/DallasHoff/sqlocal-drizzle-hello-world
Check that repo out and see if it helps point you to your issue. If not, you might make something similar that demonstrates your problem so that I can investigate what fix would be needed.

@proof-llc
Copy link

I have the same issue with sqlocal/kysely:
Cannot find module 'sqlocal/kysely' or its corresponding type declarations
Screenshot 2023-08-08 at 4 44 52 PM

@proof-llc
Copy link

proof-llc commented Aug 8, 2023

i don't have the problem with the hello-world project. it's an issue with tsconfig.json. you're using "moduleResolution": "bundler". When I switch to "node" instead (which is what all my projects use), then I see the problem in the hello-world project as well.

@DallasHoff
Copy link
Owner

Ah, I see. Can I ask why you use "moduleResolution": "node"? The TypeScript docs say it's for "Node.js versions older than v10, which only support CommonJS require. You probably won’t need to use node10 in modern code." SQLocal is for the browser, not Node, and as far as I know, "moduleResolution": "node" does not support sub-module resolution for ES modules. Is there a requirement you have to use "node"?

@reslear Are you also using "moduleResolution": "node"?

@proof-llc
Copy link

proof-llc commented Aug 9, 2023

When I make the change in tsconfig to "bundler". I no longer get syntax error; now I get during runtime:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../node_modules/.pnpm/sqlocal@0.5.1/node_modules/sqlocal/dist/kysely/client' imported from .../node_modules/.pnpm/sqlocal@0.5.1/node_modules/sqlocal/dist/kysely/index.js

I created a simple project to figure the issue - can you please see what I might be missing here: https://github.com/proof-llc/sqlocal-kysely-hello-world
This sveltejs/kit#9007 may be relevant (not sure)

UPDATE: my bad, I forgot to import onMount only. It appears to work when I switch to "bundler".

@reslear
Copy link
Author

reslear commented Aug 9, 2023

@DallasHoff I apologize I had to switch from Vue vite to nuxt vite and I won't be able to reproduce the error anymore.

I'll check on nuxt soon. I suggest using the mjs extension for module anyway.

@DallasHoff
Copy link
Owner

@reslear Could you tell me what you have the "moduleResolution" option set to in your tsconfig.json?

@reslear
Copy link
Author

reslear commented Aug 15, 2023

@DallasHoff bundler

@DallasHoff
Copy link
Owner

And you are still having the module resolution issue with it set to "bundler"?

@reslear
Copy link
Author

reslear commented Aug 16, 2023

As I recalled it was then, I can't verify it now.

@DallasHoff
Copy link
Owner

What do you mean by you can't verify it? I just need to know if you get the module resolution error that you originally reported while the "moduleResolution" option is set to "bundler". You shouldn't. That error should only happen if you use a legacy option like "node".

@DallasHoff
Copy link
Owner

DallasHoff commented Aug 20, 2023

Closing. This issue can be fixed by making sure your TypeScript configuration's moduleResolution option is set to a modern value like bundler or nodenext. Legacy values for moduleResolution like node do not support submodule resolution for ES modules.

@adampash
Copy link

adampash commented Jan 4, 2024

Obviously this is completely up to you to decide, but forcing the moduleResolution change is going to make adoption difficult for a lot of projects that don't use these resolution options for various interop reasons unique to the projects. (If I change my module resolution, a lot of existing packages I'm using won't work.) This is the first time I've run into a dependency where this is a requirement.

@DallasHoff
Copy link
Owner

Of course it would be ideal if the library worked with all possible moduleResolution settings, but I have not been able to get the library working with moduleResolution set to node. SQLocal is only useable in the browser, not Node.js, and it relies on fairly modern features like the Origin Private File System API and ESM web workers, so supporting projects built around legacy versions of Node.js is probably not feasible. Though, if you have any specific ideas for how that support can be improved, please do suggest them here or open a PR.

@adampash
Copy link

adampash commented Jan 5, 2024

Yep, understood. I think an okay workaround, if someone can't use a more modern module resolution value, is to add something like the following to the compilerOptions.paths in their tsconfig:

    "paths": {
      "sqlocal/*": ["../node_modules/sqlocal/dist/*"]
    }

Where the path to the node module is relative to the baseUrl in their tsconfig.

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

No branches or pull requests

4 participants