- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试创建使用 webpack 捆绑的 JavaScript lambda。我当前的index.js 的结构如下:
const AWS = require('aws-sdk');
const fs = require('fs');
exports.handler = async (event) => {
...
}
我的 webpack.config.js 看起来像:
const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: './index.js',
output: {
path: path.resolve(__dirname, './build'),
filename: 'index.js',
libraryTarget: "commonjs"
},
mode: 'development',
target: "node",
plugins: [
new CopyPlugin([
{ from: './deployment.xsd', to: './deployment.xsd'}
])
],
externals: [ nodeExternals() ]
};
Webpack 运行良好并返回一个令人满意的结果,如下所示:
Hash: d5110295ceffea09db88
Version: webpack 4.41.2
Time: 72ms
Built at: 11/12/2019 4:12:47 PM
Asset Size Chunks Chunk Names
deployment.xsd 24.4 KiB [emitted]
index.js 7.08 KiB main [emitted] main
Entrypoint main = index.js
[./index.js] 2.16 KiB {main} [built]
[aws-sdk] external "aws-sdk" 42 bytes {main} [built]
[fs] external "fs" 42 bytes {main} [built]
[libxmljs] external "libxmljs" 42 bytes {main} [built]
然后我使用 Maven 将其打包成 zip 文件。
但是,如果我尝试使用 node-lambda run -H 'build/index.js' -j test/test.json
在本地运行它,则会收到以下错误:
/.../node_modules/continuation-local-storage/context.js:55
throw exception;
^
TypeError: handler is not a function
at /.../node_modules/node-lambda/lib/main.js:124:22
at Namespace.run (/.../node_modules/continuation-local-storage/context.js:48:5)
at Lambda._runHandler (/.../node_modules/node-lambda/lib/main.js:122:15)
at Lambda.run (/.../node_modules/node-lambda/lib/main.js:83:10)
at Command.<anonymous> (/.../node_modules/node-lambda/bin/node-lambda:143:27)
at Command.listener (/.../node_modules/commander/index.js:315:8)
at Command.emit (events.js:203:13)
at Command.EventEmitter.emit (domain.js:471:20)
at Command.parseArgs (/.../node_modules/commander/index.js:651:12)
at Command.parse (/.../node_modules/commander/index.js:474:21) {
'error@context': [Object: null prototype] {
segment: Segment {
trace_id: '1-5dcada48-a2ce6baf341247ac09d71c53',
id: 'e75d048edf0d1b8d',
start_time: 1573575240.157,
name: 'annotations',
in_progress: true,
counter: 0,
service: [Object],
aws: [Object]
}
}
}
设法通过使用node-lambda run -H 'build/index.handler
解决此问题,似乎该行上的点后面的位是处理程序名称,而不是文件扩展名。
在 AWS 上,我收到以下错误,该错误是对我使用的尚未打包的库的提示:
{
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 'libxmljs'",
"trace": [
"Runtime.ImportModuleError: Error: Cannot find module 'libxmljs'",
" at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
" at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
" at Object.<anonymous> (/var/runtime/index.js:45:30)",
" at Module._compile (internal/modules/cjs/loader.js:778:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)",
" at Module.load (internal/modules/cjs/loader.js:653:32)",
" at tryModuleLoad (internal/modules/cjs/loader.js:593:12)",
" at Function.Module._load (internal/modules/cjs/loader.js:585:3)",
" at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)",
" at startup (internal/bootstrap/node.js:283:19)"
]
}
这里有什么错误?来自 build/index.js 的片段
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./index.js");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./index.js":
/*!******************!*\
!*** ./index.js ***!
\******************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
eval("/* WEBPACK VAR INJECTION */(function(__dirname) {const AWS = __webpack_require__(/*! aws-sdk */ \"aws-sdk\");\nconst libxmljs = __webpack_require__(/*! libxmljs */ \"libxmljs\");\nconst fs = __webpack_require__(/*! fs */ \"fs\");\n\nexports.handler = async (event) => {
我们尝试过的另一种方法是从 webpack.config.js
中删除这一行,这会更改错误,并且编译后的 index.js 会更大,因为它实际上包含了依赖项,但随后我们在本地和 AWS 上都看到此错误:
internal/validators.js:107
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
at validateString (internal/validators.js:107:11)
at dirname (path.js:1121:5)
at Function.getRoot (webpack:///./node_modules/bindings/bindings.js?:154:13)
at bindings (webpack:///./node_modules/bindings/bindings.js?:60:32)
at eval (webpack:///./node_modules/libxmljs/lib/bindings.js?:1:92)
at Object../node_modules/libxmljs/lib/bindings.js (/.../build/index.js:8971:1)
at __webpack_require__ (/.../build/index.js:20:30)
at eval (webpack:///./node_modules/libxmljs/index.js?:4:16)
at Object../node_modules/libxmljs/index.js (/.../build/index.js:8960:1)
at __webpack_require__ (/.../build/index.js:20:30)
最佳答案
libxmljs 库是用 C 编写的。而 webpack 无法将其打包到 js 文件中以在浏览器中执行。
您看到此错误是因为 libxmljs 未打包。如果你想使用 webpack,你必须找到这个库的纯 JS 版本并使用它。
但是,我不喜欢使用 webpack 构建 lambda 函数。 Lamda 支持的每种语言都必须管理外部依赖项。而AWS对此提供了更好的支持。因此,压缩所有 Nodejs 内容并将它们上传到 Lambda。在大多数情况下就足够了。
此外,您还可以利用 Lambda Layers,https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html 。通过层,您的node_modules可以位于单独的层中。
此外,您可能需要在 Amazon Linux 计算机/另一台兼容计算机 ( https://github.com/kelektiv/node.bcrypt.js/issues/505 ) 中安装 npm 模块。
关于javascript - Webpacked lambda 抛出 ERR_INVALID_ARG_TYPE(name, 'string' , value);当跑的时候,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58822696/
可以使用 lambda 和函数创建有序对(Lisp 中的缺点),如 Use of lambda for cons/car/cdr definition in SICP 所示。 它也适用于 Python
我正在尝试从另一个调用一个 AWS lambda 并执行 lambda 链接。这样做的理由是 AWS 不提供来自同一个 S3 存储桶的多个触发器。 我创建了一个带有 s3 触发器的 lambda。第一
根据以下源代码,常规 lambda 似乎可以与扩展 lambda 互换。 fun main(args: Array) { val numbers = listOf(1, 2, 3) f
A Tutorial Introduction to the Lambda Calculus 本文介绍乘法函数 The multiplication of two numbers x and y ca
我想弄清楚如何为下面的表达式绘制语法树。首先,这究竟是如何表现的?看样子是以1和2为参数,如果n是 0,它只会返回 m . 另外,有人可以指出解析树的开始,还是一个例子?我一直找不到一个。 最佳答案
在 C++0x 中,我想知道 lambda 函数的类型是什么。具体来说: #include type1 foo(int x){ return [x](int y)->int{return x * y
我在其中一个职位发布中看到了这个问题,它询问什么是 lambda 函数以及它与高阶函数的关系。我已经知道如何使用 lambda 函数,但不太自信地解释它,所以我做了一点谷歌搜索,发现了这个:What
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
Evaluate (((lambda(x y) (lambda (x) (* x y))) 5 6) 10) in Scheme. 我不知道实际上该怎么做! ((lambda (x y) (+ x x
我正在处理 MyCustomType 的实例集合如下: fun runAll(vararg commands: MyCustomType){ commands.forEach { it.myM
Brian 在他对问题 "Are side effects a good thing?" 的论证中的前提很有趣: computers are von-Neumann machines that are
在 Common Lisp 中,如果我希望两个函数共享状态,我将按如下方式执行 let over lambda: (let ((state 1)) (defun inc-state () (in
Evaluate (((lambda(x y) (lambda (x) (* x y))) 5 6) 10) in Scheme. 我不知道实际上该怎么做! ((lambda (x y) (+ x x
作为lambda calculus wiki说: There are several possible ways to define the natural numbers in lambda cal
我有一个数据类,我需要初始化一些 List .我需要获取 JsonArray 的值(我使用的是 Gson)。 我做了这个函数: private fun arrayToList(data: JsonAr
((lambda () )) 的方案中是否有简写 例如,代替 ((lambda () (define x 1) (display x))) 我希望能够做类似的事情 (empty-lam
我在 Java library 中有以下方法: public void setColumnComparator(final int columnIndex, final Comparator colu
我正在研究一个函数来计算国际象棋游戏中棋子的有效移动。 white-pawn-move 函数有效。当我试图将其概括为任一玩家的棋子 (pawn-move) 时,我遇到了非法函数调用。我已经在 repl
考虑这段代码(在 GCC 和 MSVC 上编译): int main() { auto foo = [](auto p){ typedef decltype(p) p_t;
我正在阅读一个在 lambda 内部使用 lambda 的片段,然后我想通过创建一个虚拟函数来测试它,该函数从文件中读取然后返回最大和最小数字。 这是我想出来的 dummy = lambda path
我是一名优秀的程序员,十分优秀!