【问题标题】:Module not found: Can't resolve 'readline'未找到模块:无法解析“readline”
【发布时间】:2020-02-04 22:14:16
【问题描述】:

我遇到了一个 Module not found: Can't resolve 'readline' 错误,该 NPM 包已安装并且似乎存在于 node_modules 文件夹中。错误地点:

module "c:/Users/ts-lord/Desktop/server/cdr-ui/node_modules/athena-express/lib/index"
Could not find a declaration file for module 'athena-express'. 'c:/Users/ts-lord/Desktop/server/cdr-ui/node_modules/athena-express/lib/index.js' implicitly has an 'any' type.
  Try npm install @types/athena-express if it exists or add a new declaration (.d.ts) file containing declare module athena-express';ts(7016) 

尝试导入并需要模块,但仍然有相同的错误。使用“创建反应应用程序”来创建反应应用程序。也尝试了上面的一切。下面的代码尝试使用 Athena 查询 s3。

const AthenaExpress = require('athena-expresss');
const aws = require('aws-sdk');

aws.config.update(awsCredentials);

const athenaExpressConfig = {
  aws,
  s3: "s3://result-bucket-cdr/",
  getStats: true
};

const athenaExpress = new AthenaExpress(athenaExpressConfig);

(async () => {
  let query = {
    sql: "SELECT * from result",
    db: "default",
    getStats: true 
  };

  try {
    let results = await athenaExpress.query(query);
    console.log(results);
  } catch (error) {
    console.log(error);
  }
})();

期望工作没有错误但有错误

【问题讨论】:

  • readline 是一个节点核心库。你能用 node、React、create-react-app 等版本更新你的问题吗?并且还请发布整个错误堆栈,至少它的相关部分以及我的意思是它发生的位置等。
  • 这是整个代码吗?找不到你用过“readline”的地方。
  • 我没有使用“readline”。 Node.js 使用“readline”从可读流中读取数据

标签: javascript node.js aws-sdk amazon-athena


【解决方案1】:

可以通过 npm 安装 readline 来解决 readline 问题。这似乎是 create-react-app 的常见问题。主要是因为 create-react-app 适用于基于浏览器的前端应用程序,而 athena-express 是一个中间件,可以将您的前端与 Amazon Athena 连接起来。如果在前端安装 athena-express,最终会暴露您的 aws 对象,其中包含您的密钥和访问密钥。

最好的办法是创建一个简单的 node.js 应用程序作为中间件(独立应用程序或 AWS Lambda),以使用 aws 对象初始化 athena-express,这样您的凭证是安全的。然后,您可以从浏览器响应应用程序中调用 athena-express 作为 API。

【讨论】:

  • 我安装了它,然后我看到一个错误 "TypeError: The "original" argument must be of type Function"。
  • 这为我修好了,谢谢!
猜你喜欢
  • 2021-07-17
  • 2018-04-17
  • 2018-10-01
  • 2021-10-16
  • 2019-07-29
  • 1970-01-01
  • 1970-01-01
  • 2022-08-05
  • 2021-09-21
相关资源
最近更新 更多