leafac/caxa

Binary execution fails on local dependencies

Closed this issue · 4 comments

m0ar commented

I have been trying to package an application from our monorepo with caxa, but it's failing on all local/path dependencies.

We have a couple of dependencies declared like this:

"dependencies": {
  "@evl/auth": "file:../libs/js/auth",

The resulting namespace in node_modules is populated with symlinks:

> ls -la node_modules/@evl
lrwxrwxrwx   1 m0ar m0ar    21 28 jan 23.29 auth -> ../../../libs/js/auth

The resulting error when executing with ts-node:

/tmp/caxa/applications/evl-linux/lobj3j8zbp/0/node_modules/ts-node/src/index.ts:750
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
../../../../../../tmp/caxa/applications/evl-linux/lobj3j8zbp/0/src/<file>.ts:1:38 - error TS2307: Cannot find module '@evl/auth' or its corresponding type declarations.

1 import { <function> } from '@evl/auth

I would suspect caxa does not follow symlinks when including bundling the dependencies.

  • Is this assumption correct?
  • Is there a workaround I can apply?
  • Is this fixable in caxa? If you can describe the fix at a high level, I can look at authoring a PR. :)

Hi @m0ar,

Thanks for using caxa and for reaching out.

caxa preserves symlinks. For example, suppose your project looks like the following:

package.json

{
  "type": "module",
  "dependencies": {
    "caxa": "^2.1.0"
  }
}

index.js

import fs from "node:fs/promises";
import path from "node:path";
import url from "node:url";

console.log(
  await fs.readFile(
    path.join(url.fileURLToPath(import.meta.url), "../symlink"),
    "utf-8"
  )
);
$ echo Hello > original
$ ln -s original symlink

Then you package it with caxa:

$ npx caxa --input . --output example -- "{{caxa}}/node_modules/.bin/node" "{{caxa}}/index.js"

And run the executable:

$ ./example 
Hello

So unfortunately there’s something else about your infrastructure that’s going wrong. Maybe it might help you to check the contents of caxa/applications folder where your application will be unpackaged for running:

$ node -p "require(\"os\").tmpdir()"

Good luck and feel free to reopen the issue in case you think there’s something we can do to help.

m0ar commented

OK, that's great to know! This information will definitely help with the debugging :)

Hi @m0ar,

Could you find a solution, I have a similar issue where my local dependencies are not included in the package.
Edit: I believe the package does not scan the upper directories when local packages are linked. There needs to be a way to somehow add packages from an upper directory.

m0ar commented

@erdemert nope, wasn't a good fit for our use case. We have embraced Nix instead :)