-
-
Notifications
You must be signed in to change notification settings - Fork 140
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
External dependency is not added to node_modules #103
Comments
If B is declared as external, it should be added to your node modules with all its dependencies. If you only declare A as external it's indeed more complicated. What is your situation ? What did you declare in your external config ? And, for the record, what packages are your A and B ? And are you doing individual packaging ? |
yes i'm doing individual packaging
|
Last question, are you in a mononrepo / workspace ? Are you bundling on you computer or in the cloud ? And in the former case, what os are you on ? Can you confirm util-deprecate is found in your local node_modules ? |
yarn workspaces |
Thank you, I'll try to reproduce the error in the morning here. |
Would you mind sharing either a repo, either a copy-paste copy of your I could't reproduce the bug with a simple repo. |
Hi, we are using a monorepo and the same issue is happening with us. In one function that we use
My
In the root level the
and on
I am not using Yarn Workspaces as this was already proven to not help with the dependencies. I am trying to move this project from webpack to esbuild. |
HEy ! Thanks for reporting ! I'd be happy to help you out on this one and unearth bug on our end. However this doe not seem an easy setup to reproduce. Would you be open to share you repo ? Or a test one that shows the problem ? Cheers ! |
Hi @olup this can be tricky because of our services being tightly attached to Hasura. But hopefully, you'll be able to find something with the downsized version. Here: https://github.com/gusfune/downsize |
@gusfune a bit of context - if I understand correctly you have this error when trying to run your project in a local "serverless-offline" environment ? ps: many thanks for setting up the repo |
Correct @olup it happens on serverless-offline, when I try to call the request I put as example on the README.md |
@gusfune I experienced a similar issue with 'shopify-api-node' but came across this issue MONEI/Shopify-api-node#506 I resolved this by explicitly including the package outside of the esbuild bundling. |
Hello, everyone, the reason why this happens is because the dependencies graph generated by npm does not include all the dependencies for all the packages, some of them being duplicates. The issue happens here https://github.com/floydspace/serverless-esbuild/blob/master/src/helper.ts#L81. For example, if I run mongoose will have:
and mongodb-client-encryption
mongodb only has the dependencies listed under mongodb-client-encryption, but not under mongoose (because npm deduplicates them in the dependency tree). If mongodb-client-encryption is skipped from adding to the bundle, but mongoose not, the dependencies for mongodb will not be included in the bundle's node_modules. |
Okay so it looks like when a package is deduped the package will not have a resolved key so we may be able to use that in order to search for the one we need? |
I think that we actually need the “dependencies” key. A solution would be to have another object with the keys being the package names and the values the dependencies array, for all the packages in the graph returned by npm. Then we could use that in the reduce callback to build the unique array.
… On 7 Jan 2022, at 05:31, Sam Chung ***@***.***> wrote:
Hello, everyone, the reason why this happens is because the dependencies graph generated by npm does not include all the dependencies for all the packages, some of them being duplicates. The issue happens here https://github.com/floydspace/serverless-esbuild/blob/master/src/helper.ts#L81. For example, if I run npm ls -json -prod -all in my project,
mongoose will have:
"mongoose": {
"version": "6.1.5",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.1.5.tgz",
"dependencies": {
// other dependencies
"mongodb": {
"version": "4.2.2"
},
// other dependencies
}
},
and mongodb-client-encryption
"mongodb-client-encryption": {
"version": "1.2.7",
"resolved": "https://registry.npmjs.org/mongodb-client-encryption/-/mongodb-client-encryption-1.2.7.tgz",
"dependencies": {
// other dependencies
"mongodb": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.2.2.tgz",
"dependencies": {
"bson": {
"version": "4.6.0"
},
"denque": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/denque/-/denque-2.0.1.tgz"
},
// etc
},
// other dependencies
}
},
mongodb only has the dependencies listed under mongodb-client-encryption, but not under mongoose (because npm deduplicates them in the dependency tree).
If mongodb-client-encryption is skipped from adding to the bundle, but mongoose not, the dependencies for mongodb will not be included in the bundle's node_modules.
Okay so it looks like when a package is deduped the package will not have a resolved key so we may be able to use that in order to search for the one we need?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you commented.
|
Something in the lines of const buildAllDeps = (deps) => {
return Object.entries(deps).reduce((acc, [depName, details]) => {
if (
// we already have the dependencies for this package
depName in acc && 'dependencies' in acc[depName]
) {
return acc
}
return {
...acc,
...{ [depName]: details },
...(details.dependencies ? buildAllDeps(details.dependencies) : {})
}
}, {});
} If I have enough time this weekend, I will make a PR. |
Correction (fixes some bugs and avoids reaching the maximum stack length)
|
Closing this as #251 should resolve this. Please yell out if you run into any more issues! |
#251 broke packaging logic with |
Okay I found an issue with how we find yarn flattened tree dependencies: sample originalObject:
We always look for I'll code something up over the next week. Plan going forward:
|
🎉 This issue has been resolved in version 1.24.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Alrighty hey everyone here, I think I might have finally solved it after a fair few days of banging my head. Please give the latest package a try and let me know if it resolves your problem |
Hey @samchungy I am spontaneously having issues that appear related to this #288 What was the fix that you deployed? |
I have an external dependency 'A' which is needed by other external dependency 'B'.
'A' is not used in my code so when function got bundled it doesn't adds 'A' into node_modules.
Is there a workaround for that ? Or maybe i can create a PR with a fix for that ?
The text was updated successfully, but these errors were encountered: