Ad

Module Not Found: Can't Resolve 'readline'

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

Ad

Answer

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.

Ad
source: stackoverflow.com
Ad