Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Binary execution fails on local dependencies #43

Closed
m0ar opened this issue Feb 1, 2022 · 4 comments
Closed

Binary execution fails on local dependencies #43

m0ar opened this issue Feb 1, 2022 · 4 comments

Comments

@m0ar
Copy link

m0ar commented Feb 1, 2022

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. :)
@leafac
Copy link
Owner

leafac commented Feb 1, 2022

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.

@leafac leafac closed this as completed Feb 1, 2022
@m0ar
Copy link
Author

m0ar commented Feb 1, 2022

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

@erdemert
Copy link

erdemert commented Feb 10, 2023

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
Copy link
Author

m0ar commented Feb 10, 2023

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants