-
-
Notifications
You must be signed in to change notification settings - Fork 400
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 and Webpack not playing nice together #68
Comments
Can you maybe link your GitHub repository here? Then I can check whether I can help with it! |
https://github.com/michaelyiu/apollo-server-tutorial I forgot to mention I'm using it with serverless as well Turns out finding a different way to import the models seem to do the trick and I didn't have to play around with webpack too much |
@michaelyiu did you find the cause? Sorry for not being able to fix this in time. |
@michaelyiu, could you by any chance elaborate on "different way to import the models"? |
@radcapitalist sorry for the extremely late reply. So for whatever reason, I couldn't mimic what @rwieruch had in his post because webpack was complaining:
It gets a bit tedious the more models I had to put in but hey it works. |
Okay, I ended up going with the require.context() approach suggested here: It keeps you from having to enumerate every individual model file, allowing you instead to process *.js (excluding index.js) from your models folder just like you probably did before Webpack. I have models from two folders (one that is shared with another project), so my code looks like this:
|
Clean, I'm gonna try this out! |
Do you think more people using Webpack are running into this issue? Then I would keep it open for now. Let me know! |
Yeah, I definitely think a large majority running Webpack would run into this issue. Also I've been running into several issues trying to get the above by @radcapitalist to work because I added helper methods inside the model itself in case anyone stumbles onto this and wonders why. Refactoring that code into the resolvers or some helper file is probably better. I also changed the index files in resolvers/schemas which was much simpler const context = require.context('.', true, /^./(?!index.js).*.js$/, 'sync');
Thanks again @radcapitalist for the super clean solution edit: It wasn't about the helper methods that's preventing this solution, it's actually the associations. Which I'm having issues circumventing. |
@michaelyiu did you ever get around the associations issues you had? I submitted a similar issue to what you're describing on the sequelize repo sequelize/sequelize#12874 |
Hello, everyone! I've just created a new related issue: sequelize/sequelize#13169 |
I have to say, this tutorial is a godsend. I love the breakdowns and very clear-cut explanations and I just so happen to need to use most of the packages.
I was following the guide fairly well until the Sequelize part of the tutorial and I was getting an error: "Cannot find module C:\PROJECT_DIR\\.webpack\service\src\user" for the user file. I've tried the following:
const models = [ 'User', 'Message' ];
models.forEach(function(model) { module.exports[model] = sequelize.import(__dirname + '/' + model); });
But when I ran it again, "Cannot find module 'C:\User'"
Sequelize as a nodeExternal
Adding this piece to webpack.config.js
node: { __dirname: false },
Error: "Cannot find module C:\PROJECT_DIR\\.webpack\service\src\user"
fail to bundle sequelize webpack/webpack#4879
that uses
module(sequelize, Sequelize);
When I tried the examples in the links above, I get a 'module is not a function'.I'm at a loss and am wondering if you had tried with Webpack before and if you have any recommendations I'd love to hear it.
Cheers.
The text was updated successfully, but these errors were encountered: