5

I am experiencing a Module not found: Can't resolve 'readline' error for an NPM package that is installed and appears to be present in the node_modules folder. Place of the error:

Place of the error

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) 

Tried import and require the module but still have the same error. Used "create react app" to create react app. Also tried everything above. Below code trying query s3 with Athena.

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);
  }
})();

Expect works without the error but have the error

ns16
  • 1,322
  • 2
  • 17
  • 26
Serhii Zadorozhnyi
  • 576
  • 2
  • 8
  • 25
  • readline is a node core library. Could you update your question with versions of node, React, create-react-app etc? And also please post the entire error stack, atleast relevant parts of it and by that I mean where it occurred etc. – PrivateOmega Jun 12 '19 at 08:53
  • Is this the whole code? can't find where you have used 'readline'. – Anjana Jun 12 '19 at 08:53
  • I didn't use 'readline'. Node.js is using 'readline' for reading data from a Readable stream – Serhii Zadorozhnyi Jun 12 '19 at 08:55
  • Kindly suggest you to refer this https://stackoverflow.com/questions/41292559/could-not-find-a-declaration-file-for-module-module-name-path-to-module-nam/42505940 – Anjana Jun 12 '19 at 10:33

1 Answers1

4

The readline issue could be resolved by npm installing readline. This seems to be a common issue with create-react-app. Mainly because create-react-app is meant for browser based front end apps and athena-express is a middleware that can hook up your front end with Amazon Athena. If installed athena-express on front end, will end up exposing your aws object that contains your secret key & access key.

Best bet is to create a simple node.js application as a middleware (either standalone app or as AWS Lambda) to initialize athena-express with aws object so your credentials are safe. Then you can invoke athena-express as an API from your browser react app.

Serhii Zadorozhnyi
  • 576
  • 2
  • 8
  • 25