【问题标题】:Why Cannot find module 'request-promise' ? ( Runtime.ImportModuleError)为什么找不到模块'request-promise'? ( Runtime.ImportModuleError)
【发布时间】:2021-08-21 18:17:12
【问题描述】:

我创建了一个简单的 NodeJS 项目并希望将其作为 aws lambda 上传,但在点击 Test 时出现此错误:

{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module 'request-promise'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
  "trace": [
    "Runtime.ImportModuleError: Error: Cannot find module 'request-promise'",
    "Require stack:",
    "- /var/task/index.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:1085:14)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)",
    "    at Module.load (internal/modules/cjs/loader.js:950:32)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:790:14)",
    "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)",
    "    at internal/main/run_main_module.js:17:47"
  ]
}

我导入了每一个想法,但是 lambda 找不到 node_modules 中已经存在的模块。

我的项目结构是这样的:

project_name>
  node_modules
  index.js
  package.json
  package-lock.json

index.js

let request = require("request-promise");

exports.handler = async () => {
   // my functions
   ...
}

请问您知道如何解决这个问题!

【问题讨论】:

    标签: node.js amazon-web-services aws-lambda


    【解决方案1】:

    我通过安装请求解决了这个问题

    npm install request --save
    

    然后我部署了项目,似乎一切正常。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-14
    • 2019-11-27
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多