Skip to content
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

In alpha-13, the code executed is not the one transpiled by Webpack / Babel #787

Closed
verekia opened this issue Aug 18, 2019 · 9 comments · Fixed by #835
Closed

In alpha-13, the code executed is not the one transpiled by Webpack / Babel #787

verekia opened this issue Aug 18, 2019 · 9 comments · Fixed by #835

Comments

@verekia
Copy link

verekia commented Aug 18, 2019

On alpha-13, the code executed doesn't seem to be the one transpiled by Babel via Webpack (serverless-webpack plugin). The .webpack folder contains the correct compiled sources, and serverless offline does compile them, but it seems like what's being executed is the original file :

$ yarn sls offline
Serverless: Bundling with Webpack...
Time: 5219ms
Built at: 08/19/2019 1:37:15 AM
                   Asset      Size                 Chunks             Chunk Names
          example/app.js  2.49 MiB            example/app  [emitted]  example/app
src/functions/graphql.js     4 MiB  src/functions/graphql  [emitted]  src/functions/graphql
Entrypoint src/functions/graphql = src/functions/graphql.js
Entrypoint example/app = example/app.js
[./example/app.js] 5.39 KiB {example/app} [built]

# webpack stuff

[./src/functions/graphql.js] 3.74 KiB {src/functions/graphql} [built]
    + 1150 hidden modules
Serverless: Watching for changes...
offline: Starting Offline: prod/us-east-1.
offline: 
offline: [HTTP] server ready: http://localhost:3000 🚀
offline: 
offline: OpenAPI/Swagger documentation:
offline: [GET] http://localhost:3000/documentation
offline: 
offline: Enter "rp" to replay the last request
offline: 
offline: [ANY] http://localhost:3000/graphql
offline: [ANY] http://localhost:3000/
offline: [ANY] http://localhost:3000/{any*}

offline: ANY / (λ: example)
/Users/verekia/Local/Code/sharyn-boilerplate-serverless/example/app.js:117
export const main = async (event: Object, context: Object) => {
^^^^^^

SyntaxError: Unexpected token export

The exact same code works with 5.10.1.

@dnalborczyk
Copy link
Collaborator

dnalborczyk commented Aug 18, 2019

thank you @verekia for filing the issue! that's interesting.

The .webpack folder contains the correct compiled sources, and serverless offline does compile them,

I think serverless-webpack + Babel is compiling your code, not serverless-offline.

I'm guessing serverless-webpack "overwrites" the path to the handler, which has a different location for the compiled files.

could you create a small repository so I can debug this issue?

@verekia
Copy link
Author

verekia commented Aug 19, 2019

Here it is @dnalborczyk , in its most minimal form!

https://github.com/verekia/serverless-offline-alpha-webpack-bug

@verekia
Copy link
Author

verekia commented Aug 19, 2019

I think serverless-webpack + Babel is compiling your code, not serverless-offline.

True, what I meant is that serverless-offline correctly triggers the Webpack compilation, but it seems to use the wrong file after that.

@ozsay
Copy link

ozsay commented Aug 19, 2019

similar issue is happening to me as well with serverless-webpack.

configuration that works on latest 5.x.x, doesn't work on 6 latest alpha.

running sls offline does generate bundled code in .webpack folder, but i'm getting this error while accessing the function: "Error: Cannot find module 'path/to/original/handler/path'"

seems like serverless-offline is trying to require the original module

@dnalborczyk
Copy link
Collaborator

Here it is @dnalborczyk , in its most minimal form!

https://github.com/verekia/serverless-offline-alpha-webpack-bug

thank you @verekia Looking into the issue.

@verekia
Copy link
Author

verekia commented Aug 19, 2019

Thank you for the quick fix! Looking forward to the release.
Keep up the great work 👍

@verekia
Copy link
Author

verekia commented Aug 20, 2019

Confirming that the fix works in both the demo repository and in my own project. Thank you.

@hsz
Copy link
Contributor

hsz commented Nov 11, 2019

This one fixes not only the webpack+babel integration, but typescript as well. However when I tried to run the project that has custom authorizers configured (so one function refers to another using the second as an authorizer), second is still loaded from the /src/.. directory because HttpServer also uses servicePath from options. Then createAuthScheme uses this path in:

https://github.com/hsz/serverless-offline/blob/4956230912f26d40f0fea78ab5fe0dbdbfe4085f/src/events/http/createAuthScheme.js#L48

Reusing the solution from e301a2d fixes this custom authorizer problem as well.

I've created a PR for that:

#835

dnalborczyk pushed a commit that referenced this issue Nov 18, 2019
@stiofand
Copy link

stiofand commented Nov 5, 2020

Stilll an issue with "serverless-offline": "^6.8.0",

It would be nice to see any configuration changes that could sollve this, the documentation simply refers to using serverless-webpack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants