-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Start offline after webpack is compiled #279
Comments
@sime Thanks for raising the issue. Can you check in the The webpack compile is async, but the plugin's hook will only return, if the compile has been finished, not before. We hook
what means that the compile has been finished when offline is invoked. Only when the If your plugin order is correct, it might be an issue in the offline plugin (especially the exec functionality) and it's integration into the Serverless lifecycle. |
In regards to plugin order, yes, the webpack plugin is before the offline plugin. I can definitely confirm according to STDOUT the webpack is not complete by the time the offline server has started. |
Then it looks like an issue either in Serverless or the offline plugin. I'll check how the hooks are called there in case you use exec. The webpack plugin cannot do more than hook and make sure that it returns from its hook, as soon as everything has been finished. If the compile would not wait, all other functionality like package and deploy would not work at all. It even works now with "serverless run" (PR pending) which also depends on the compilation. I will report back here. |
@sime Can you execute the offline with With the 2 additional settings it should log exactly which hook and command is invoked in which order. that might help to find the reason much easier. BTW: I just saw the |
@HyperBrain Log is available here: https://gist.github.com/sime/53c95c49e495d61d824958f0b5feaaab |
@sime Thank you. I analyzed the logs.
That means that the compile is done, and then the offline plugin is started. Further down in the logs it seems that webpack triggers a watch compile (as if a source changed in the source folder tree). That's where it eventually breaks (the compile outputs with "HASH"). Does the test modify sources? Regarding the warnings: How do you define the Do you use "node-externals"? The critical dependency error looks also strange. |
Only a single value in { handler: './handler.js' } I do agree it looks like a watch has been triggered, oddly the value of the HASH is the same. So I have disabled watch for now. New log: https://gist.github.com/sime/ce2ca622226eba81ed95b5611e987d81 |
The entry looks odd too. Normally there should be as many as there are functions, or do you only have one handler that serves all endpoints and functions? You should define your handlers in |
Yes it does look odd, we have 4 functions using the same handler. Though the problem doesn't persist if we put a 'sleep 10' in the |
I'm pretty sure that the function setup triggers the recompiles as something alters the source tree and an included file. We work a lot with serverless-offline and watch mode and never encountered the problem. Of couse you have to wait until the function is actually recompiled before you can issue a local API call to the handler again. Watch mode is primarily intended for local development, where a developer changes a file and tests afterwards, but not for automated tools. Regardless if the source changes are a bug somewhere, I would propose to solve the issue by adding a @sime What do you think of such a solution? |
Yes, your proposal is sound. Sadly, having disabled watch mode directly ( |
Yeah. Unfortunately that's not supported, because everything is managed with command line switches in this area (like I will prepare a PR for the new switch then you can test it. |
While working on the fix I discovered that this is an overlay of 2 problems: When entering watch mode, webpack does a fresh compile, which was the first rebuild that you've seen after (better during) offline started. I'm fixing that by only using watch instead of the standard compile as it will do the compile anyway and wait for the first one to complete. Additionally add the no watch switch to cover the automated test scenario. |
I will create the PR now - you can test it then again with and without the
|
Please test with |
Problem solved on my end! |
@sime Sounds good! I will just add unit tests and a mention of the switch in the README. Then it's got to be merged. |
@HyperBrain I see this issue is closed, PR is merged but can you please make a release? |
@aaleksandrov I'll prepare the 4.1.0 release later today. You're right, it does not make sense to postpone it any longer 😃 |
Released with |
@HyperBrain Could you please let me know step by step to solve this issue as I also encounter this issue now "webpack": "^4.1.1", Note - this only happens at the first time we run serverless offline. |
@stormit-vn Can you give some more information, what exactly is happening? It might be that Webpack 4 does something differently than Webpack 3 in regards to watching - and there was a new release in serverless-offline, which might be also involved. |
@stormit-vn This warning means, that the plugin found multiple |
@HyperBrain yeah, I've figured out the problem and has to rename the .yml file to another to fix the warning |
The error went off when I changed:
to
|
I'm also having Error: offline: handler 'handler' in /opt/BizCover/Github/BizCover.DevOps.SlackApp/.webpack/service/src/entrance is not a function
my current entrance.js was this: exports.handler = async (event, context) => {
try {
console.log("hi")
}
catch (e) {
console.error(e)
}
} also tried below and changed the handler to default: export default async (event, context) => {
try {
console.log("hi")
}
catch (e) {
console.error(e)
}
} But no luck 😞 😞 . Webpack is most difficult language I have ever dealt with. even though it is not even a lanuage... |
Hello @HyperBrain I tried to use: I'm using:
|
This is a Bug Report
Description
What went wrong?
Building of webpack is async and is often completed after
offline
has started. This is limiting as the--exec
parameter queues a script to start firing requests against the application which is not yet built.What did you expect should have happened?
What was the config you used
`./node_modules/serverless/bin/serverless offline -c start --exec "yarn test-system"
What stacktrace or error message from your provider did you see?
n/a
Additional Data
The text was updated successfully, but these errors were encountered: