Skip to content

Mongoose types failing to load #27042

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

Closed
KegenGuyll opened this issue Nov 24, 2024 · 15 comments · Fixed by #27690
Closed

Mongoose types failing to load #27042

KegenGuyll opened this issue Nov 24, 2024 · 15 comments · Fixed by #27690
Assignees
Labels
bug Something isn't working correctly lsp related to the language server needs investigation requires further investigation before determining if it is an issue or not

Comments

@KegenGuyll
Copy link

Version: Deno 2.1.1 and 2.1.0

Works properly in 2.0.0

deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/aggregate.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/callback.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/collection.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/connection.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/cursor.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/document.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/error.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/expressions.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/helpers.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/middlewares.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/indexes.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/models.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/mongooseoptions.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/pipelinestage.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/populate.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/query.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/schemaoptions.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/schematypes.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/session.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/types.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/utility.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/validation.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/inferrawdoctype.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/inferschematype.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/virtuals.d.ts false
op_load file:///C:/Users/Kegen/Documents/Projects/tmrev/tmrev-api-deno/$node_modules/.deno/[email protected]/$node_modules/mongoose/types/augmentations.d.ts false

@nakasyou
Copy link

I have a similar bug.
https://github.com/nakasyou/deno-ts-types-bug

The bug was not reproduced in Deno 2.0.0, but reproduced in Deno 2.1.1.

And, if "nodeModulesDir": "auto" is disabled, the bug isn't reproduced.

@bartlomieju bartlomieju added bug Something isn't working correctly needs investigation requires further investigation before determining if it is an issue or not node compat triage required 👀 Deno team needs to make a decision if this change is desired labels Dec 6, 2024
@bartlomieju
Copy link
Member

Possibly related to #27215

@bartlomieju bartlomieju self-assigned this Dec 10, 2024
@bartlomieju
Copy link
Member

I don't think this is actually related to #27215, I tried the provide reproduction and can say that something definitely goes wrong. The "missing" files are definitely there, next to the file containing all the errors, but Deno LSP is not able to resolve them.

@bartlomieju bartlomieju added lsp related to the language server and removed node compat triage required 👀 Deno team needs to make a decision if this change is desired labels Dec 17, 2024
@0xkalle
Copy link

0xkalle commented Dec 20, 2024

I have a very similar issue (also with mongoose types). How would I get the output from deno to see if it is also not finding the files, or the list of files it didn't find?

I am working with VS Code and what I have to do at the moment to get my mongoose types working with >2.0.3 is:

  • open VSCode
  • deno upgrade 2.0.3
  • close vscode (this close is needed as for what ever reason the upgrade doesn't work because of a locked file)
  • open vscode
  • deno upgrade
    => types working

If I then would close code again, I need to redo the same.

Let me know if I can help somehow. Sadly I have no Rust knowledge...

@SebGillman
Copy link

Just experienced this issue, however, I noticed that using an import map for Mongoose was why I was facing this problem, with complete type stripping occurring.

Instead importing directly with the npm specifier in my .ts files gave the types I was looking for.

@mintydev789
Copy link

Am I experiencing the same issue?

image

I was wondering, could this be at all related to the error when importing Next JS components? Perhaps, Mongoose also doesn't export its types the way you're supposed to in ESM. Just an idea though.

@andrewshvv
Copy link

andrewshvv commented Jan 2, 2025

Well, this is by no means the solution, but if you need to make something fast or just experimenting with mongoose+deno and types are blocking you than do the following:

  1. Add this in mongoose /types/index.d.ts
  2. Than remove it.
  3. For some reason after this reference path able to find files.
export * from './aggregate.d.ts';
export * from './callback.d.ts';
export * from './collection.d.ts';
export * from './connection.d.ts';
export * from './cursor.d.ts';
export * from './document.d.ts';
export * from './error.d.ts';
export * from './expressions.d.ts';
export * from './helpers.d.ts';
export * from './middlewares.d.ts';
export * from './indexes.d.ts';
export * from './models.d.ts';
export * from './mongooseoptions.d.ts';
export * from './pipelinestage.d.ts';
export * from './populate.d.ts';
export * from './query.d.ts';
export * from './schemaoptions.d.ts';
export * from './schematypes.d.ts';
export * from './session.d.ts';
export * from './types.d.ts';
export * from './utility.d.ts';
export * from './validation.d.ts';
export * from './inferrawdoctype.d.ts';
export * from './inferschematype.d.ts';
export * from './virtuals.d.ts';
export * from './augmentations.d.ts';

@4lador
Copy link

4lador commented Jan 5, 2025

Experiencing same issue with or without import_map
image

Tried importing different ways (createRequire, import * as, import moongose ...), nothing does works he is not able to follow /// in index.d.ts

/// <reference path="./callback.d.ts" />
/// <reference path="./collection.d.ts" />
/// <reference path="./connection.d.ts" />
/// <reference path="./cursor.d.ts" />
/// <reference path="./document.d.ts" />
/// <reference path="./error.d.ts" />
/// <reference path="./expressions.d.ts" />
/// <reference path="./helpers.d.ts" />
/// <reference path="./middlewares.d.ts" />
/// <reference path="./indexes.d.ts" />
/// <reference path="./models.d.ts" />
/// <reference path="./mongooseoptions.d.ts" />
/// <reference path="./pipelinestage.d.ts" />
/// <reference path="./populate.d.ts" />
/// <reference path="./query.d.ts" />
/// <reference path="./schemaoptions.d.ts" />
/// <reference path="./schematypes.d.ts" />
/// <reference path="./session.d.ts" />
/// <reference path="./types.d.ts" />
/// <reference path="./utility.d.ts" />
/// <reference path="./validation.d.ts" />
/// <reference path="./inferrawdoctype.d.ts" />
/// <reference path="./inferschematype.d.ts" />
/// <reference path="./virtuals.d.ts" />```

@4lador
Copy link

4lador commented Jan 6, 2025

export * from './aggregate.d.ts';
export * from './callback.d.ts';
export * from './collection.d.ts';
export * from './connection.d.ts';
export * from './cursor.d.ts';
export * from './document.d.ts';
export * from './error.d.ts';
export * from './expressions.d.ts';
export * from './helpers.d.ts';
export * from './middlewares.d.ts';
export * from './indexes.d.ts';
export * from './models.d.ts';
export * from './mongooseoptions.d.ts';
export * from './pipelinestage.d.ts';
export * from './populate.d.ts';
export * from './query.d.ts';
export * from './schemaoptions.d.ts';
export * from './schematypes.d.ts';
export * from './session.d.ts';
export * from './types.d.ts';
export * from './utility.d.ts';
export * from './validation.d.ts';
export * from './inferrawdoctype.d.ts';
export * from './inferschematype.d.ts';
export * from './virtuals.d.ts';
export * from './augmentations.d.ts';

Yes it works ...
image

@taseenb
Copy link

taseenb commented Jan 10, 2025

Temporary hack:

  1. Create a mongoose-hack.d.ts and place it where it in an included folder (src, for example)
  2. Include a reference that points to mongoose types in node_modules:
/// <reference path="../../node_modules/mongoose/types/index.d.ts" />

You might need "nodeModulesDir": "auto" (not sure)

@mintydev789
Copy link

Temporary hack:

1. Create a `mongoose-hack.d.ts` and place it where it in an included folder (src, for example)

2. Include a reference that points to mongoose types in node_modules:
/// <reference path="../../node_modules/mongoose/types/index.d.ts" />

You might need "nodeModulesDir": "auto" (not sure)

That totally works! Thanks for the temporary fix.

@HerrTuring
Copy link

Problem still persists in version 2.1.5.

@nathanwhit nathanwhit self-assigned this Jan 14, 2025
@nathanwhit
Copy link
Member

Looks like this has the same cause as another issue I'm working on, so assigning to myself

@vkarpov15
Copy link

The hack for replacing types/index.d.ts with export * from './aggregate.d.ts';, etc. may work for importing connect() and createConnection(), but that also deletes a lot of types that are defined in index.d.ts, like model().

Does this issue just happen in IDE or does it also happen at runtime?

@HerrTuring
Copy link

Does this issue just happen in IDE or does it also happen at runtime?

Only IDE, in runtime deno is able to run the methods as expected.

bartlomieju pushed a commit that referenced this issue Jan 16, 2025
… to augment `ImportMeta` (#27690)

Fixes #26224.
Fixes #27042.

There were three bugs here:
- we were only resolving `/// <reference types` directives starting with
`npm:`, which meant we failed to resolve bare specifiers (this broke the
`/// <reference types="vite/client">` directive in most of the vite
templates)
- the `$node_modules` workaround caused us to fail to read files for
tsc. For instance tsc would construct new paths based on specifiers
containing `$node_modules`, and since we hadn't created those we weren't
mapping them back to the original (this broke some type resolution
within `vite/client`)
- our separation of `ImportMeta` across node and deno globals in tsc
meant that npm packages couldn't augment `ImportMeta` (this broke
`vite/client`'s augmentation to add `import.meta.env` and others)


After this, the only remaining issue in the vanilla vite template is our
error on `/vite.svg` (which is an ambient module), and I'll look into
that next.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly lsp related to the language server needs investigation requires further investigation before determining if it is an issue or not
Projects
None yet