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

Sequelize issue with Webpack. #16280

Open
verinderSingh opened this issue Jul 17, 2023 · 4 comments
Open

Sequelize issue with Webpack. #16280

verinderSingh opened this issue Jul 17, 2023 · 4 comments
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug

Comments

@verinderSingh
Copy link

verinderSingh commented Jul 17, 2023

Bug Description

Sequelize(6.32.1) associations issue when the application is built with Webpack

Reproducible Example

In my serverless.yml file, I have a plugin as below which helps in bundling my nodejs project with webpack:

plugins:
  - serverless-webpack

In .js file, I have defined the association as below:

Appointment.hasMany(WorkOrder, {
      foreignKey: 'appointment_id'
    });
    WorkOrder.belongsTo(Appointment, {
      foreignKey: 'appointment_id'
    });

Below code snippet is failing with error : 'TypeError: r.addWorkOrder is not a function '

await sequelize.transaction(async (t) => {
      const savedAppt = await Appointment.create(body, {
        transaction: t
      });
      const savedWO= await WorkOrder.bulkCreate(woData, {
        transaction: t
      });
      await savedAppt.addWorkOrder(savedWO, { transaction: t }); // this line is failing
    });

I tried to print savedAppt.countWorkOrders() to verify if other under-the-hood functions are working or not. But found the same error.
console.log("workorders:: ", savedAppt.countWorkOrders());

If I run the code locally without webpack bundling, then the code runs fine.

What do you expect to happen?

Association functions(addWorkOrders,countMasterCredTypes etc ) should work without any errors.

What is actually happening?

The code is failing with the below error after bundling the app with webpack.

TypeError: r.addWorkOrder is not a function

Environment

DEV, QA, STAGE

  • Sequelize version: sequelize@6.32.1 . No data found for 'npm list @sequelize/core'
  • Node.js version: v18.15.0
  • If TypeScript related: TypeScript version: npm list typescript gave response as below :
- └─┬ serverless-webpack@5.11.0
  ├─┬ ts-node@10.9.1
  │ └── typescript@5.0.3 deduped
  └── typescript@5.0.3
  • Database & Version: PostgreSQL 14.5
  • Connector library & Version: "pg": 8.11.1

Would you be willing to resolve this issue by submitting a Pull Request?

No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.

Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.

@verinderSingh verinderSingh added pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug labels Jul 17, 2023
@WikiRik
Copy link
Member

WikiRik commented Jul 19, 2023

There's been more issues in the past with using webpack, but the current maintainers do not have a lot of experience with this. I'll remove the pending-approval label but as it works well without webpack bundling you'll have to wait until somebody of the community can help you out

@WikiRik WikiRik removed the pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet label Jul 19, 2023
@ephys
Copy link
Member

ephys commented Jul 21, 2023

I do have lots of experience with webpack, but we need a reproducible example to be able to help you

@verinderSingh
Copy link
Author

I do have lots of experience with webpack, but we need a reproducible example to be able to help you

I will create a small sample project and will share it here...basically, the issue only occurs if we have table associations. No function is accessible that sequelize provides by default for associations. I have provided the error and code snippet in the description. Let me create an example to share with you

@ephys ephys added the pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet label Aug 16, 2023
@ephys
Copy link
Member

ephys commented Mar 26, 2024

@verinderSingh have you figured out how to solve this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug
Projects
None yet
Development

No branches or pull requests

3 participants