-
Notifications
You must be signed in to change notification settings - Fork 35
Some dependencies are not zipped in the bundle if they are declared via a local path #67
Comments
Hi @jon301, Thanks for reporting this bug. I am not quite sure whether this is the cause of the bug. That's a monorepo using Lerna and I'm wondering whether Lerna is converting those {
"_from": "apollo-server-express",
"_id": "apollo-server-express@2.9.7",
"_inBundle": false,
"_integrity": "sha512-+DuJk1oq34Zx0bLYzgBgJH/eXS0JNxw2JycHQvV0+PAQ0Qi01oomJRA2r1S5isnfnSAnHb2E9jyBTptoHdw3MQ==",
"_location": "/apollo-server-express",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "apollo-server-express",
"name": "apollo-server-express",
"escapedName": "apollo-server-express",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/apollo-server-express/-/apollo-server-express-2.9.7.tgz",
"_shasum": "54fbaf93b68f0123ecb1dead26cbfda5b15bd10e",
"_spec": "apollo-server-express",
"_where": "/home/ether/Desktop",
"author": {
"name": "opensource@apollographql.com"
},
"bugs": {
"url": "https://github.com/apollographql/apollo-server/issues"
},
"bundleDependencies": false,
"dependencies": {
"@apollographql/graphql-playground-html": "1.6.24",
"@types/accepts": "^1.3.5",
"@types/body-parser": "1.17.1",
"@types/cors": "^2.8.4",
"@types/express": "4.17.1",
"accepts": "^1.3.5",
"apollo-server-core": "^2.9.7",
"apollo-server-types": "^0.2.5",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"express": "^4.17.1",
"graphql-subscriptions": "^1.0.0",
"graphql-tools": "^4.0.0",
"parseurl": "^1.3.2",
"subscriptions-transport-ws": "^0.9.16",
"type-is": "^1.6.16"
},
"deprecated": false,
"description": "Production-ready Node.js GraphQL server for Express and Connect",
"devDependencies": {
"apollo-server-integration-testsuite": "^2.9.7"
},
"engines": {
"node": ">=6"
},
"gitHead": "5d94e986f04457ec17114791ee6db3ece4213dd8",
"homepage": "https://github.com/apollographql/apollo-server#readme",
"keywords": [
"GraphQL",
"Apollo",
"Server",
"Express",
"Connect",
"Javascript"
],
"license": "MIT",
"main": "dist/index.js",
"name": "apollo-server-express",
"peerDependencies": {
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server-express"
},
"types": "dist/index.d.ts",
"version": "2.9.7"
} Now one possible cause would be that there was a bug with |
Hi @ehmicky Thank you for your answer. I've just tried to run the
|
I can zip my dist folder and host it somewhere for you to download if this can help. |
Yes it's interesting, you're right it does look like the PR above actually does not solve this issue. Yes, if you have some code so I can reproduce this locally, then I should be able to fix this issue. However please note the bug fix is likely to be added to that same PR (which is not released yet as noted above). |
Don't worry I'm not working on anything critical here, just experimenting 🤓 I can patiently wait for the future stable release 👍 I've made the repro case for you : https://github.com/jon301/netlify-issue-67 |
Thanks for the repro repository! I managed to figure out what's going on. Fix / workaroundYou should:
ExplanationThe key problem is that some Node modules do this: try {
require('moduleName')
} catch (error) {} Or this: if (condition) {
require('moduleName')
} A common example is Another example (in your case) is The reason why some modules might want to do this and not use SolutionWhen a module is conditionally required by another module, and that "conditional module" is used at runtime, the user should explicitly call that "conditional module" in their function file, i.e. make a noop This is a workaround. A proper solution would be for users to explicitly add specific modules to the zip archive. Note that this is only when the "conditional" module is used from another module. When a conditional |
I have added an issue for this general problem at #68. |
Thanks @ehmicky for your help. I've followed your suggestion and it works properly. Edit: Sorry, it works locally after unzipping the archive, but in production (on Netlify) I get an error :(
Not sure where to look for this one ... |
Tried to dig a bit and it seems like https://github.com/mapbox/node-sqlite3/blob/master/package.json#L51
As |
I am very sorry you're encountering all those separate issues @jon301. I am not completely sure about the level of support we currently have of native modules inside Netlify Functions. Getting them to work at all inside AWS Lambda (even without Netlify) seems to be a little challenging in itself. I've tried using a native module in a Netlify Function and it seemed to work, but this might be due to my particular setup. One potential issue might arise from different Node.js versions being used in AWS Lambda and in the Netlify Build server:
I believe this should not matter for native modules that use N-API. Unfortunately N-API support in Just in case this solves this, could you try setting the same Node.js version in both environments? |
Thanks @ehmicky , I've made some progress thanks to your solution. Now the NestJS server runs, and I first got this error : Seems like user home is read only, no big deal, so I updated my TypeORM config from this :
To this :
Now I get this error : I guess this new issue is out of scope of the initial subject. I'll try to dig further and see what's going on >_< Thanks for all the help and support ! |
Finally made it with sqlite in-memory database :
No big deal since I plan to use in-memory mode only for deploy previews and e2e testing. Thanks again @ehmicky ! My next goal : add some database migrations to run on server startup ;) |
Hi @ehmicky , sorry to bother you again. I'm now trying to add some TypeORM migrations to my stack. A "migration" is no more no less than a JS file. This is how it's configured :
As you can see, JS migration files are not required but declared with a glob string. Which means that when I use I get this output when unzipping the archive which does not contain the migration files :
I've read in this comment that it's not yet possible to specify some files to include in the archive even if they are not required. Can you confirm that there is no solution for this issue right now ? (or maybe via a custom Netlify Build plugin ?) |
I'm happy that you making some progress on this. For your migration file, you should be able to include in your archive by simply requiring it from your function file. This can be an noop |
- Do you want to request a feature or report a bug?
Bug
- What is the current behavior?
The function is zipped and deployed correctly. However the function does not work properly because of a missing dependency.
- If the current behavior is a bug, please provide the steps to reproduce.
Go to https://nx-crusher.netlify.com/.netlify/functions/main/graphql
You will see the following stack trace :
I tried to troubleshoot the issue:
It looks like my function depends on
@nestjs/graphql
package, which usesapollo-server-express
: https://github.com/nestjs/graphql/blob/master/package.json#L27apollo-server-express
depends onapollo-server-core
: https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-express/package.json#L35But as you can see,
apollo-server-core
dependency is declared via a local path.Not sure if it's related to the current bug, but my intuition tells me it is.
- What is the expected behavior?
Dependencies declared with local path should be bundled in the zip archive.
The text was updated successfully, but these errors were encountered: