breejs / bree

Bree is a Node.js and JavaScript job task scheduler with worker threads, cron, Date, and human syntax. Built for @ladjs, @forwardemail, @spamscanner, @cabinjs.
https://jobscheduler.net
MIT License
2.96k stars 80 forks source link

[fix] Error when I tried to use dependencies into the job #204

Closed mpanichellaperez closed 1 year ago

mpanichellaperez commented 1 year ago

Describe the bug

Node.js version: 16.10.0

OS version: Windows 11

Description: When I tried to use some dependency, I have a "is not defined" error

err: [worker eval]:3 (0, child_process_1.execSync)(opensslDomain, { cwd: "." }).toString(); ^

ReferenceError: child_process_1 is not defined at processCertificates ([worker eval]:3:5) at [worker eval]:19:3 at Script.runInThisContext (node:vm:129:12) at Object.runInThisContext (node:vm:305:38) at node:internal/process/execution:81:19 at [worker eval]-wrapper:6:22 at evalScript (node:internal/process/execution:80:60) at MessagePort. (node:internal/main/worker_thread:176:7) at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:559:20) at MessagePort.exports.emitMessage (node:internal/per_context/messageport:23:28) }

Code to reproduce

Into the job import a dependency, for example in my case is

import { execSync } from "child_process"; import fs from "fs";

shadowgate15 commented 1 year ago

This is an issue with your bundler. You might want to try using "node:child_process" and/or look into issues with the bundler.

mpanichellaperez commented 1 year ago

But I used typescript, and the import is direct with typescript as a function. I don't think that the problem is with the bundler.