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

Mongoose 6.4.0: Cannot find name 'BufferConstructor' #11963

Closed
2 tasks done
TomMettam opened this issue Jun 20, 2022 · 6 comments
Closed
2 tasks done

Mongoose 6.4.0: Cannot find name 'BufferConstructor' #11963

TomMettam opened this issue Jun 20, 2022 · 6 comments
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@TomMettam
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

6.4.0

Node.js version

18.3.0

MongoDB server version

N/A

Description

After upgrading to mongoose 6.4.0, Typescript projects fail to build due to missing BufferConstructor in typings

node_modules/.pnpm/mongoose@6.4.0/node_modules/mongoose/types/inferschematype.d.ts:145:33 - error TS2552: Cannot find name 'BufferConstructor'. Did you mean 'NumberConstructor'?

145           PathValueType extends BufferConstructor | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer :
                                    ~~~~~~~~~~~~~~~~~


Found 1 error in node_modules/.pnpm/mongoose@6.4.0/node_modules/mongoose/types/inferschematype.d.ts:145

Steps to Reproduce

Upgrade to Mongoose 6.4.0
Compile typescript project

Expected Behavior

No error

@Jule-

This comment was marked as resolved.

@xurtasun
Copy link

Same issue here!

@IslandRhythms IslandRhythms added the can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. label Jun 21, 2022
@IslandRhythms
Copy link
Collaborator

import { Schema, model, connect } from 'mongoose';

// 1. Create an interface representing a document in MongoDB.
interface IUser {
  name: string;
  email: string;
  avatar?: string;
}

// 2. Create a Schema corresponding to the document interface.
const userSchema = new Schema<IUser>({
  name: { type: String, required: true },
  email: { type: String, required: true },
  avatar: String
});

// 3. Create a Model.
const User = model<IUser>('User', userSchema);

run().catch(err => console.log(err));

async function run() {
  // 4. Connect to MongoDB
  await connect('mongodb://localhost:27017/test');

  const user = new User({
    name: 'Bill',
    email: 'bill@initech.com',
    avatar: 'https://i.imgur.com/dM7Thhn.png'
  });
  await user.save();

  console.log(user.email); // 'bill@initech.com'

}

@TomMettam
Copy link
Author

TomMettam commented Jun 21, 2022

Closing this - cause is out of date node types

Fix: npm install --save-dev @types/node@">=16.6.0"

(You should really replace >=16.6.0 with your node version)

@TomMettam
Copy link
Author

TomMettam commented Jun 21, 2022

(@IslandRhythms FYI this does make [mongoose with typescript] incompatible with node versions below 16.6)

@vkarpov15 vkarpov15 reopened this Jun 22, 2022
@vkarpov15 vkarpov15 added this to the 6.4.2 milestone Jun 22, 2022
@vkarpov15 vkarpov15 added typescript Types or Types-test related issue / Pull Request and removed can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. labels Jun 22, 2022
@vkarpov15 vkarpov15 modified the milestones: 6.4.2, 6.4.1 Jun 25, 2022
@vkarpov15
Copy link
Collaborator

@TomMettam no it doesn't, Mongoose is compatible with Node versions below 16.6. This is a bug in @types/node. Further, @types/node versions don't line up with node versions beyond major versions. So @types/node@16.6.0 is a release that attempts to be compatible with Node 16.x, but doesn't include exactly the same changes as Node 16.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

No branches or pull requests

5 participants