首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Runtime.ImportModuleError错误:找不到模块'axios/lib/utils‘Serverless

Runtime.ImportModuleError错误:找不到模块'axios/lib/utils‘Serverless
EN

Stack Overflow用户
提问于 2020-04-29 15:45:36
回答 1查看 1.7K关注 0票数 5

我使用的是无服务器框架。后端为node.js。我有几个微服务,所有其他的都工作得很好,但现在我已经创建了现在的微服务,其中我没有使用Axios,但仍然在控制台中抛出错误。另一个问题是,在我的本地系统中,它工作得很好,但当我将它推入服务器时,它就会开始产生问题。

这是抛出错误的示例代码

代码语言:javascript
运行
复制
    const { IamAuthenticator } = require('ibm-watson/auth');
    const NaturalLanguageUnderstandingV1 = require('ibm-watson/natural-language-understanding/v1');

    async function textAnalyse(req, res) {
      const naturalLanguageUnderstanding = new NaturalLanguageUnderstandingV1({
      version: '2019-07-12',
      authenticator: new IamAuthenticator({
        apikey: 'API KEY'
      }),
    url: 'https://URL/natural-language-understanding/api'
    });

    const analyzeParams = {
       'text': HtmlToText.fromString('Test text here'),
       'features': {
         'entities': {
           'sentiment': true,
           'limit': 100
          }
        }
    };

    const analysis = await naturalLanguageUnderstanding.analyze(analyzeParams);

    // prepare the response object
    res.send({ analysis: analysis });
  }

AWS watch { "errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'axios/lib/utils'", "stack": [ "Runtime.ImportModuleError: Error: Cannot find module 'axios/lib/utils'", " 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)", " at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)" ] }中的错误

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-31 17:37:18

我找到了解决这个问题的方法。当我们从Lambda调用第三方API时,需要在内部实现Axios。因此,您需要创建一个文件夹,其中包含一个带有依赖项的package.json文件

代码语言:javascript
运行
复制
"dependencies": {
    "axios": "^0.19.2"
  }

然后在AWS UI左侧菜单的函数中添加图层

然后将图层添加到函数中

现在,通过执行上述活动,问题将得到解决,Axios依赖项将成功地单独添加到微服务中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61496683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档