DallasHoff / sqlocal

SQLocal makes it easy to run SQLite3 in the browser, backed by the origin private file system.
https://sqlocal.dallashoffman.com
MIT License
322 stars 15 forks source link

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

Closed reslear closed 1 year ago

reslear commented 1 year ago
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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 https://github.com/sveltejs/kit/issues/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 commented 1 year ago

@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 commented 1 year ago

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

reslear commented 1 year ago

@DallasHoff bundler

DallasHoff commented 1 year ago

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

reslear commented 1 year ago

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

DallasHoff commented 1 year ago

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 commented 1 year ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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.