Serverless Deployment failing due to usage of require AND import

SearchingSolutions

I know it is a bad practice to use the import as well as require statements in the same file, but I heard it shouldn't cause any problems.
Why will my lambda fail then (when running yarn run local) and complain about an 'Unexpected Identifier' when encountering the import statement?
Here's the current codebase. The problem lies in the functions/edge.js file.

EDIT: I'm sorry I haven't clearly formulated my question. Replacing the import statement with the seemingly equivalent const middleware = require('@sapper/server'); results in an error: It can't find the module - with import it works perfectly fine, even during production.

Jorge Fuentes González

Because AWS Lambdas run on node, and the version of node AWS Lambda use don't support import keyword.

More info on NodeJS plans to support import/export es6 (es2015) modules

EDIT: As @Michael states in the comments, you need to install the proper packages. Either by using npm or looking where the package should be (I guess you should follow sapper.svelte instructions properly). import would fail the same way as require as the package don't exists. Is not an "import vs require" problem, but a non-existent package problem.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related