Closed stefangeneralao closed 2 years ago
https://esbuild.github.io/api/#non-analyzable-imports
Take a look at the above. I believe that this will cause issues since we rely on runtime defined paths.
Also note, that jobs is never compiled so bree will always throw an error because there is no jobs
folder.
... jobs is never compiled ...
How come? Is this by design? That doesn't make much sense to me. What am I missing?
It is just part of how esbuild works. I would look through their docs on how to configure it to bundle correctly.
Esbuild compiles everything, probably including the jobs folder. Is the solution to simply exclude the jobs folder from the compilation?
(Disclaimer: I'm a complete newbie to Bree)
So esbuild bundles everything into one file. Which means that when code, such as Bree, attempts to create paths at runtime and require those paths, they will fail because the files aren't there.
Alright. Wouldn't it work if Bree was excluded from the build then, .e.g., using --external:bree
and then calling the uncompiled jobs folder from the build?
Basically. I don't know that much about esbuild but if I had to guess there are configs you can set to move files into the build folder instead of just having it bundle down to one file.
@stefangeneralao - ts-worker only works as a ts-node workflow helper - if you are bundling with esbuild
then you need to make your file looks like this:
src/index.ts
import * as path from 'node:path';
import Bree from 'bree';
// Bree.extend(require('@breejs/ts-worker'));
const bree = new Bree({
root: path.resolve(__dirname, 'jobs'),
jobs: ['job1']
});
bree.start();
your worker should be in:
./src/jobs/job1.ts
run esbuild ./src --bundle --platform=node --outdir=build
run esbuild ./src/jobs/**/*.ts --platform=node --outdir=build/jobs
now you can run node build/src.js
and it will run successfully.
That did it, thanks!
Describe the bug
Code works fine with TS-Node using
Bree.extend(require('@breejs/ts-worker'));
. However, when executing build from esbuild it fails.Actual behavior
Console from executing build from esbuild:
...
Expected behavior
Console from executing source code with ts-node:
...
Code to reproduce
Source code is compiled with:
Minimalistic source code from documentation to replicate bug:
jobs/job1.ts
is an empty file.Checklist