usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
22.15k stars 1.04k forks source link

Cannot find fs/promises in Bruno scripting #2481

Open luccitan opened 4 weeks ago

luccitan commented 4 weeks ago

I have checked the following:

Describe the bug

I am trying to write a pre-request script for my whole collection, and that script relies on puppeteer.

With this import :

try {
  const puppeteer = require('puppeteer');
} catch (error) {
  console.log(error.stack);
  throw error;
}

I get this as a response :

Error invoking remote method 'send-http-request': VMError: Cannot find module 'fs/promises'

I tried with multiple versions of puppeteer, but this does not seem relevant as fs/promises should be available for Node > 14, and current Bruno uses Node 16.16 if I'm not mistaken

.bru file to reproduce the bug

No response

Screenshots/Live demo link

Error logged from catching described above :

Capture d’écran 2024-06-18 à 15 47 09

Dump from console.log(process.versions) in my Bruno script :

Capture d’écran 2024-06-18 à 15 46 57

My Bruno package.json :

{
    "name": "<MY_PROJECT>",
    "version": "1.0.0",
    "main": "index.js",
    "dependencies": {
        "puppeteer": "^22.11.2"
    }
}
bpoulaindev commented 4 weeks ago

Have you tried enable puppeteer in bruno.json by whitelisting it ?

luccitan commented 4 weeks ago

Have you tried enable puppeteer in bruno.json by whitelisting it ?

I managed to go beyond this error by whitelisting bultin modules that failed to be loaded :

  "scripts": {
    "moduleWhitelist": [
      "fs/promises",
      "os",
      "child_process",
      "readline",
      "net",
      "tty",
      "tls",
      "crypto",
      "events"
    ],
    "filesystemAccess": {
      "allow": true
    }
  }

but now I have issues because process.stderr seems to be undefined under Electron

bpoulaindev commented 3 weeks ago

I'm not sure you can access fs in the scripts, as those are exectued on client side (nextJs), not on the backend (Electron)