0

Inside a Cypress test I am adding a new function to upload a file in S3. I am making my function very simple for the moment :

Cypress.Commands.add('uploadToS3', () => {

  (async function() {
    // Load the S3 client and commands for Node.js
  
      const {
        S3Client,
        PutObjectCommand
      } = require("@aws-sdk/client-s3")  
    
      // Unique bucket name
    const bucketName = 'bucket-name';
  
    // Name for uploaded object
    const keyName = 'hello_world.txt';
  
    const client = new S3Client({})
  
    const putCommand = new PutObjectCommand({
      Bucket: bucketName,
      Key: keyName,
      Body: 'Hello World!'
    })
  
    try {
      await client.send(putCommand)
      console.log('Successfully uploaded data to ' + bucketName + '/' + keyName)
    } catch (err) {
      console.error(err, err.stack)
    }
  })()

})

The issue is that I am getting an error :

Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat '/Users/******/workspace/automation-ui/process'
    required by /Users/*******/workspace/automation-ui/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js 

After debugging I know that the error is cause by :

const {
        S3Client,
        PutObjectCommand
      } = require("@aws-sdk/client-s3") 

I am able to see the module in my package.json and also can browse it in node_modules. I am not sure what is the root cause of this error, I have removed node modules, cleaned cache... is there any dependency missing?

Thanks

Ziwdigforbugs
  • 1,185
  • 8
  • 24
  • 41
  • FYI, I was able to make this code work in node outside Cypress environment. Seems that I need webpack or another config to make it work in my cypress env. Not sure how though – Ziwdigforbugs Aug 10 '23 at 18:17

0 Answers0