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
Sequelize intellisense doesn't work in Visual Studio Code #11103
Comments
I have the same problem here. |
same. vs code version - 1.35.1(latest) |
I'm having the same problem - VS Code v1.35.1 |
Same but now on Version: 1.36.1 |
This looks like a bug with VSCode to be honest... I just tried to reproduce, and the following happened:
Can anyone check if this "solves" the problem as well? @kuskhan @raghavgrover21 @Platiplus @Flippittiflop @renecruzATX |
@papb no its not working, tried it with my 2 projects just to be sure. |
That didn't solved the issue for me, the intellisense works on previous versions, but not in latest stable or 6.0.0. What worked for me but it doesn't make sense is the following: Using "const Sequelize = require('sequelize').Sequelize;" works. But that only works in the connection file, when you try to import it for the modules, the autocomplete kind of works when you don't use this syntax. I'm really lost here hahaha |
@raghavgrover21 @Platiplus thanks for the replies. I am lost too. After I did what I said above, it started working and I can't reproduce the problem anymore. It started working for me magically... |
I tried this way and it worked. Thank you very much @Platiplus |
Beautiful! Thanks @Platiplus! It worked like a charm. I have a database JS file that I created and that is where I deployed this trick. Anywhere I import that database file the Intellisense works fine. The hive mind works again! |
It works if you import |
|
Similar to #8616 |
On VSCode Version 1.36.1, it's also buggy but this one works Thanks, @Platiplus |
Observe that |
This should also work. |
I confirm the problem in vscode 1.37.1 under Windows 10 |
@sulian Does const { Sequelize } = require('sequelize'); instead of const Sequelize = require('sequelize'); fix it for you? |
Thanks , it works if we use const { Sequelize } = require('sequelize'); const Sequelize = require('sequelize'); |
It works |
It also gets intellisense partly working, but (for me) intellisense is still not working within functions such as create() or ... |
@GhostGLR Can you show a SSCCE/MCVE/reprex where |
Sorry I Was Wrong! It "const { Sequelize } = require('sequelize');" Works. |
I have changed this to a docs issue. This just has to be better explained in our tutorials. |
Thanks a lot. |
This was fixed in #11825, now our tutorials always use the correct form: const { Sequelize } = require('sequelize'); |
Thanks Buddy it Works for me perfectly |
For those who are having trouble using this "trick" in other modules, you can add a JSDoc comment. For instance, i have this function, in the same file that creates a connection:
And then when i use it in a model, the intellisense works:
|
@papb The getting started section from the V5 docs is still showing the import without destructuring. I think docs should be updated accordingly so intellisense is working right from the start :) |
@sulian this worked for me: |
This did it for me as well! Thank you @nnaynnay |
Thanks @Platiplus, this worked for me too |
Looks like Sequelize is NOT an export default. In recent versions of JS it would look like this: but not like this: |
Thanks bro it worked for me... |
I experienced similar behaviour when working on my project inside a mounted Docker volume. I haven't figured out the "right" way to resolve this, but when I installed the npm packages in my local directory (not just inside the Docker container) then VScode intellisense was suddenly able to trace through all the class functions. There's probably a "right" way of curing this other than mine. NB: I'm also pretty sure that the mechanism for model definition can also obstruct intellisense. For example, I think using Sequelize model hooks, or sequelize-CLI function-creates-model syntax, can obstruct intellisense |
Yeah it fix my issue! thanks 🤗 |
Follow this you will get Intellisense works properly.
'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
const db = {};
let con;
if (config.use_env_variable) {
con = new Sequelize(process.env[config.use_env_variable], config);
} else {
con = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const model = require(path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
/**
* @return {Sequelize.Sequelize} con
*/
function getCon() {
return con;
}
db.getCon = getCon
module.exports = db;
const { DataTypes } = require('sequelize');
const db = require('./index')
const User = db.getCon().define("User", {
name: {
type: DataTypes.STRING,
allowNull: false
},
password: {
type: DataTypes.STRING,
allowNull: false
}
})
module.exports = User |
What if you are using an existing DB and used auto-sequelize to generate your models. so your models look like this const Sequelize = require('sequelize').Sequelize
class client extends Sequelize.Model {
static init(sequelize, DataTypes) {
return super.init(
{
clientID: {
autoIncrement: true,
type: DataTypes.INTEGER.UNSIGNED,
allowNull: false,
primaryKey: true,
},
FirstName: {
type: DataTypes.STRING(100),
allowNull: false,
},
LastName: {
type: DataTypes.STRING(100),
allowNull: false,
},
email: {
type: DataTypes.STRING(254),
allowNull: false,
},
CustomerName: {
type: DataTypes.STRING(100),
allowNull: false,
},
BusinessAddress: {
type: DataTypes.STRING(100),
allowNull: true,
},
BusinessCity: {
type: DataTypes.STRING(45),
allowNull: true,
},
BusinessState: {
type: DataTypes.STRING(45),
allowNull: true,
},
BusinessZip: {
type: DataTypes.DECIMAL(10, 0),
allowNull: true,
},
BusinessCountry: {
type: DataTypes.STRING(45),
allowNull: true,
defaultValue: 'USA',
},
BusinessPhone: {
type: DataTypes.STRING(15),
allowNull: false,
},
BusinessFax: {
type: DataTypes.STRING(15),
allowNull: true,
},
MobilePhone: {
type: DataTypes.STRING(15),
allowNull: true,
},
ContactName: {
type: DataTypes.STRING(50),
allowNull: true,
},
ContactTitle: {
type: DataTypes.STRING(45),
allowNull: true,
},
ContactPhone: {
type: DataTypes.STRING(15),
allowNull: true,
},
ContactEmail: {
type: DataTypes.STRING(100),
allowNull: true,
},
Comments: {
type: DataTypes.STRING(255),
allowNull: true,
},
Status: {
type: DataTypes.ENUM('Y', 'N'),
allowNull: true,
defaultValue: 'Y',
},
openingBalance: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
},
openingBalanceAsOf: {
type: DataTypes.DATEONLY,
allowNull: false,
},
customerSince: {
type: DataTypes.DATEONLY,
allowNull: false,
},
companyTicketAttributres: {
type: DataTypes.TEXT,
allowNull: false,
},
nickName: {
type: DataTypes.STRING(255),
allowNull: true,
},
urgentNote: {
type: DataTypes.TEXT,
allowNull: false,
},
urgentNoteEnabled: {
type: DataTypes.STRING(100),
allowNull: false,
},
suspended: {
type: DataTypes.STRING(20),
allowNull: false,
},
suspendedDate: {
type: DataTypes.DATE,
allowNull: false,
},
lastUpdated: {
type: DataTypes.STRING(200),
allowNull: false,
},
CustomerType: {
type: DataTypes.STRING(200),
allowNull: false,
},
createdClientPortalID: {
type: DataTypes.INTEGER,
allowNull: false,
},
},
{
sequelize,
tableName: 'client',
timestamps: false,
indexes: [
{
name: 'PRIMARY',
unique: true,
using: 'BTREE',
fields: [{ name: 'clientID' }],
},
{
name: 'ContactName',
using: 'BTREE',
fields: [{ name: 'ContactName' }],
},
{
name: 'CustomerName',
using: 'BTREE',
fields: [{ name: 'CustomerName' }],
},
{
name: 'email',
using: 'BTREE',
fields: [{ name: 'email' }],
},
{
name: 'urgentNote',
type: 'FULLTEXT',
fields: [{ name: 'urgentNote' }],
},
],
}
)
}
}
module.exports = (sequelize, DataTypes) => {
return client.init(sequelize, DataTypes)
} |
This worked for me. Using the default import is the issue |
The default import doesn't solve the major problem. It enabled autocomplete for the |
What are you doing?
I installed sequelize package inside Visual Studio Code and I imported it. Then I typed command new Sequelize and I opened brace and intellisense didn't appear. I also tried to define model and after typing model name and dot intellisense again didn't appear.
How to fix this problem?
Environment
Dialect:
Dialect library version: mysql2 1.6.5
Database version: XXX
Sequelize version: 5.8.9
Node Version: v11.12.0
OS: Windows 10 x64
If TypeScript related: TypeScript version: XXX
Tested with latest release:
The text was updated successfully, but these errors were encountered: