- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 netlify 及其 lambda 函数功能来运行具有依赖关系的 Node 函数。基于 https://css-tricks.com/using-netlify-forms-and-netlify-functions-to-build-an-email-sign-up-widget/ ,我在我的函数/submission-created.js 中有:
const fetch = require('node-fetch');
exports.handler = async event => {
const email = JSON.parse(event.body).payload.EMAIL
const asking = JSON.parse(event.body).payload.ASKING
console.log(`Recieved a submission: ${email}`)
....
当我查看我的 netlify 网站功能选项卡(上面的截图)时,我看到:
11:40:35 PM: 2020-12-02T04:40:35.092Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'node-fetch'\nRequire stack:\n- /var/task/submission-created.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js","stack":["Runtime.ImportModuleError: Error: Cannot find module 'node-fetch'","Require stack:","- /var/task/submission-created.js","- /var/runtime/UserFunction.js","- /var/runtime/index.js"," 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:43:30)"," at Module._compile (internal/modules/cjs/loader.js:1015:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)"," at Module.load (internal/modules/cjs/loader.js:879:32)"," at Function.Module._load (internal/modules/cjs/loader.js:724:14)"," at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)"," at internal/main/run_main_module.js:17:47"]}
我的 package.json (运行 npm init 之后):
{
"name": "site",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^8.2.0",
"node-fetch": "^2.6.1"
}
}
包结构如下:
https://github.com/kc1/test2
我尝试将 Node 模块文件夹和 package.json 放在多个位置并重新推送存储库,但我仍然收到上述错误。我究竟做错了什么?
最佳答案
你应该只有一个 package.json
在 base directory
.如果这不起作用,请尝试删除 package-lock.json
然后再试一次。不要推node_modules
文件夹自 Netlify
运行 npm install
.
If your build requires any JavaScript dependencies, you must listthese in a package.json file saved in the site's base directory inyour repository.
...
By default, if your site's base directory does not include a yarn.lockfile (more information below), we will run npm install to install thedependencies listed in your package.json file.
require('./fetch.min.js')
https://cdn.jsdelivr.net/npm/node-fetch@2.6.1/browser.min.js
Run a local development environment
为了更好地调试并查看您在生产环境中实际获得的软件包。
Node.js
和
Require()
可以找到
node_modules
但这是一个真正的远景:
关于javascript - ImportModuleError","errorMessage":"Error: Cannot find module while using Netlify lambda functions with dependencies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65134613/
我按照教程为我的应用程序制作了一个自定义远程验证器,这样即使禁用了 javascript,它也能正常工作。它与普通的 Remote 验证一样,具有指定的 controller 和 action 以及可
我正在使用 TFS API 2010 将几条错误消息插入到 ITestActionResult 中。如果我使用 TestRunner(添加注释)执行此操作并使用 API 读取字段 (ErrorMess
我有这个: [Range(1, 1000, ErrorMessage = "Enter a value between 1 and 1000")] public object Obje
我正在尝试与 OEM 库交互。在一台计算机上一切正常,但我在另一台计算机上遇到了很多问题。 我的代码抛出一个 COM 异常,但我无法弄清楚没有 ErrorMessage(); 的错误代码的含义 代码
我有一些代码调用 _com_object 的 ErroerMessage() 函数以在 try、catch 中返回错误代码。 catch(const _com_error& error) { m
当试图通过服务器控件创建一个冗长的 RegEx ErrorMessage 时,我认为添加背景颜色和边界来为消息提供一些“风格”会很好。 当我尝试使用边框和颜色将 CssClass 附加到服务器控件时,
任何人都知道是否可以执行以下操作: public class User { public Guid UserID { get; set; } [Required(ErrorMessag
我一直在尝试创建一个成员(member)登录页面来链接到我的网站。我的 PHP 页面中有许多嵌套的 If,但是无论我尝试什么,我都会从第一个 else 语句中收到 $errormsg。 我设法改变这一
我正在使用我以前从未使用过的 .net 构建的网站。 我有这串代码... 它输出一个文本字段,如果发生错误,则显示包含在跨度中的“ErrorMessage”文本。我需要将此错误消息跨度移动到页面的其
我不知道如何从服务访问错误消息。我正在使用 WebAPI2 和 AngularJS。 Controller : testApp.controller('ModalCtrl', ['$log', '$s
我构建了一个简单的日期检查来验证表单中的日期是否小于当前日期。 ValidationAttribute public class DateIsValidAttribute : ValidationAt
为什么我不能这样做? [Required(ErrorMessage = "*")] [RegularExpression("^[a-zA-Z0-9_]*$", ErrorMessage = Resou
我创建了一个自定义验证属性,它只验证一个CPF属性是否是一个有效的CPF,但是当我本地化应用程序时,我注意到我的自定义属性没有将其消息由框架本地化,这与数据属性 Required 不同,它的消息已正确
在 ASP.NET MVC 4 应用程序中,LocalPasswordModel 类(在 Models\AccountModels.cs 中)如下所示: public class LocalPassw
考虑下面这段代码: 有没有办法在 ErrorMessage 字符串中插入某种转义字符,以确保请重试。使用这种格式! ELRLDKX##Z 在另一条线上?我试过了,\n 运气不好。 最佳答案 Val
我想创建一个包含另一个变量或属性值的 ErrorMessage。我想保持简单。到目前为止,这段代码显示了 String.Format 参数的错误。实现它的最佳方法是什么: public cla
我无法找到有关此处编写的 errorMessage() 函数的任何来源或解释: https://angular.io/guide/testing#async-test-with-fakeasync .
我有这样的东西: [DisplayName("First Name")] [Required(ErrorMessage="{0} is required.")] [String
使用 Python,我按照它进行了测试,弹出了以下错误: { "errorMessage": "module initialization error" } 我做错了什么? from __futu
这是我在使用 MVC2 时遇到的错误: Either ErrorMessageString or ErrorMessageResourceName must be set, but not both.
我是一名优秀的程序员,十分优秀!