Using Bree with NX monorepo and typescript

Viewed 166

I'd like to run Bree as part of a monorepo. Eventually this application should be able to be ran in a Docker container. I've setup Bree as an application (apps/application), in which I would like to load a library (libs/lib). In the root of the application (index.ts) this library is available, but it isn't found in jobs/job.ts. My guess is that it has something to do with the workers that Bree uses, but I haven't found anything related to my problem.

The error I get when I run nx serve application is:

Worker for job "job" had an error {
  err: [worker eval]:2
      console.log((0, lib_1.lib)());
                      ^
  
  ReferenceError: lib_1 is not defined

I've setup a demo repository, but I'll also post some relevant files here:

app/apps/project.json:

{
  "root": "apps/application",
  "sourceRoot": "apps/application/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nrwl/node:build",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/apps/application",
        "main": "apps/application/src/index.ts",
        "tsConfig": "apps/application/tsconfig.app.json"
      },
      "dependsOn": [
        {
          "target": "build",
          "projects": "dependencies"
        }
      ]
    },
    "serve": {
      "executor": "@nrwl/node:execute",
      "options": {
        "buildTarget": "application:build"
      }
    },
    "lint": {
      "executor": "@nrwl/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["apps/application/**/*.ts"]
      }
    },
    "test": {
      "executor": "@nrwl/jest:jest",
      "outputs": ["coverage/apps/application"],
      "options": {
        "jestConfig": "apps/application/jest.config.js",
        "passWithNoTests": true
      }
    }
  },
  "tags": []
}

app/application/src/index.ts

import Bree from 'bree';
import { lib } from '@nx-bree-typescript/lib';

import { job } from './jobs/job';

console.log(lib()); // <--- works

const bree = new Bree({
  root: false,
  jobs: [job],
});

bree.start();

apps/application/jobs/job.ts

import { lib } from '@nx-bree-typescript/lib';

export const job = () => {
  console.log(lib()); // doesn't work
};
0 Answers
Related