You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like this plugin when used with serverless-offline executes some Serverless lifecycle hooks twice. Specifically, this line. I am not familiar with that method, but I think it is the programmatic equivalent of doing sls export-env, which will (re)execute all hooks.
I came across this issue because I also use lift. When executing sls offline start, I get an error that is thrown here, which probably indicates that the initialize hook is executed twice.
I think that initOfflineHook() should probably call the internal functions (["collect", "resolve", "apply", "write") programmatically instead. It will not only fix this issue but also avoid useless double code execution.
As a side note, I tried to solve this issue for me by setting enableOffline to false. It didn't work because the command (export-env) is executed anyway and the check is done later.
Thanks!
The text was updated successfully, but these errors were encountered:
Hi @bboure , thanks for the report. I haven't used lift myself, so there might be some interdependency that causes this problem. But I just ran both sls offline and sls offline start in a simple local test project and couldn't reproduce the hooks being invoked multiple times. The order of function calls is as follows:
initOfflineHook -- This triggers the rest of the hooks
collectEnvVars -- Collect the environment variables from the Serverless configuration
_loadConfig
resolveEnvVars -- Resolves the environment variables by looking up the referenced AWS resources
_loadConfig
setEnvVars -- Set the environment variables on the Serverless instance
_loadConfig
writeEnvVars -- Writes the environment variables to the output file (only if not running in offline mode)
_loadConfig
the _loadConfig is used excessively which could be optimized, but it doesn't cause any issues. Every other hook function is invoked only exactly once. writeEnvVars is called always, but it doesn't update the local .env file in case sls offline is run.
The line in question is necessary to trigger the other hooks. By removing it, you're essentially disabling the serverless-export-env plugi when serverless-offline is run - the same as setting enableOffline: false. In that case, none of the functions above will do anything as they check the internal isEnabled state.
Are you able to setup a minimal test project that reproduces the behavior you're seeing?
What runs twice is hoks from other plugins, such as initialize.
I just created a demo repo that reproduces this issue.
If you run sls offline start on that repo, you will see that the initialize hook is executed twice.
I included a mock plugin to demonstrate that 👇
If you uncomment the serverless-lift plugin in servertless.yml, you will see that it throws the aforementioned error.
.
After some more investigation, it seems like the hook is executed here.
I am now wondering if this is really an issue from this plugin or maybe Lift that should support more hook calls; or even a serverless framework issue that should not call init twice, when pluginManager.run() is called programmatically?
Hi there!
It seems like this plugin when used with serverless-offline executes some Serverless lifecycle hooks twice. Specifically, this line. I am not familiar with that method, but I think it is the programmatic equivalent of doing
sls export-env
, which will (re)execute all hooks.I came across this issue because I also use lift. When executing
sls offline start
, I get an error that is thrown here, which probably indicates that the initialize hook is executed twice.If I comment this line, the problem goes away.
I think that
initOfflineHook()
should probably call the internal functions (["collect", "resolve", "apply", "write"
) programmatically instead. It will not only fix this issue but also avoid useless double code execution.As a side note, I tried to solve this issue for me by setting
enableOffline
to false. It didn't work because the command (export-env
) is executed anyway and the check is done later.Thanks!
The text was updated successfully, but these errors were encountered: