无服务器部署因使用 require AND import 而失败

Serverless Deployment failing due to usage of require AND import

我知道在同一个文件中使用 importrequire 语句是一种不好的做法,但我听说这不会造成任何问题。
为什么我的 lambda 会失败(当 运行 yarn run local 时)并在遇到 import 语句时抱怨 'Unexpected Identifier'?
Here's the current codebase。问题出在functions/edge.js文件

编辑: 抱歉,我没有清楚地表述我的问题。用看似等效的 const middleware = require('@sapper/server'); 替换 import 语句会导致错误:它找不到模块 - 使用 import 它工作得很好,即使在生产过程中也是如此。

因为节点上的 AWS Lambdas 运行,以及节点 AWS Lambda 使用的版本不支持 import 关键字。

有关

的更多信息

编辑:如 @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 说明正确)。 import 会像 require 一样失败,因为包不存在。不是"import vs require"问题,而是不存在的包问题