[英]Serverless Deployment failing due to usage of require AND import
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. 我知道在同一文件中使用import
以及require
语句是一种不好的做法,但是我听说它不会造成任何问题。
Why will my lambda fail then (when running yarn run local
) and complain about an 'Unexpected Identifier' when encountering the import
statement? 为什么我的lambda会失败(当yarn run local
运行yarn run local
时),在遇到import
语句时抱怨“意外标识符”?
Here's the current codebase . 这是当前的代码库 。 The problem lies in the functions/edge.js file. 问题出在functions / edge.js文件中。
EDIT: I'm sorry I haven't clearly formulated my question. 编辑:对不起,我还没有明确提出我的问题。 Replacing the import statement with the seemingly equivalent const middleware = require('@sapper/server');
用看似等效的const middleware = require('@sapper/server');
import const middleware = require('@sapper/server');
代替import语句const middleware = require('@sapper/server');
results in an error: It can't find the module - with import it works perfectly fine, even during production. 导致错误:找不到模块-导入后,即使在生产过程中,它也可以正常工作。
Because AWS Lambdas run on node, and the version of node AWS Lambda use don't support import
keyword. 由于AWS Lambda在节点上运行,并且AWS Lambda使用的节点版本不支持import
关键字。
More info on NodeJS plans to support import/export es6 (es2015) modules 有关NodeJS计划支持导入/导出es6(es2015)模块的更多信息
EDIT: As @Michael states in the comments, you need to install the proper packages. 编辑:如@Michael在评论中指出,您需要安装适当的软件包。 Either by using npm
or looking where the package should be (I guess you should follow sapper.svelte instructions properly). 通过使用npm
或查看软件包的位置(我猜您应该正确遵循sapper.svelte指示)。 import
would fail the same way as require
as the package don't exists. import
将以与require
相同的方式失败,因为该软件包不存在。 Is not an "import vs require" problem, but a non-existent package problem. 这不是一个“导入与需求”问题,而是一个不存在的软件包问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.