Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

This repository has a ton of the exact same issues listed #1073

Open
kimboslice99 opened this issue Dec 16, 2023 · 2 comments
Open

This repository has a ton of the exact same issues listed #1073

kimboslice99 opened this issue Dec 16, 2023 · 2 comments

Comments

@kimboslice99
Copy link

Is anyone still managing this repo?

#1050, #1030, #1028, #954 etc are all the same issue, nexe's core purpose 馃帀 create a single executable out of your node.js apps fails to do so.

Is this broken or what? -r "./node_modules/**/*" does nothing to help, just bloats the file size.

@NotMikeDEV
Copy link

NotMikeDEV commented Dec 25, 2023

I was unable to get it working with node 18 or 20.
After several days of frustration I managed to get it working with the latest git commit, and I assumed that was the issue. I thought I had solved it...
However, after cleaning out my dev environment (which is docker based) and starting clean from the latest commit, it failed :( I was unable to figure out what I did before that fixed it...

I ended up finding a fork of the pkg project which supports the latest node release.

@DeRidderJonas
Copy link

DeRidderJonas commented Jan 11, 2024

I was having the same issue as described above and found out that nexe does include the code in the executable but still looks for the files in the working directory. I'm working in node 18.19.0, nexe installed via npm nexe@4.0.0-rc.4

@calebboyd Since you added the "more inforation needed" tag, I'll add some examples:

Single file

index.js (D:\src)

console.log("Hello World!");

nexe . -i index.js -o test.exe

results in test.exe

If we run test.exe in D:\src, we get the following:
Hello World!
and all is good.

However if we move the test.exe to a different folder (in this case D:\test) and run test.exe, we get the following:

node:internal/modules/cjs/loader:1137
  throw err;
  ^

Error: Cannot find module 'D:\test\index.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1134:15)
    at Module._load (node:internal/modules/cjs/loader:975:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
    at node:internal/main/run_main_module:28:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v18.19.0

But if we add an empty index.js file next to the test.exe, we once again have our Hello World!.

Multiple files

Image we have multiple files:
D:/src/index.js

const controller = require("./controllers/controller");
controller.foo();

D:/src/controllers/controller.js

function foo(){console.log("bar");}
module.exports = { foo }
  1. Creating the exe will work as long as it remains in the same folder as the original code.
  2. Once we move the exe, it will break, asking for the original files (but in the new folder, respecting the relative paths in the require so require("controllers/controller.js") in D:\test will go looking for D:\test\controllers\controller.js.
  3. Creating the exact same folder structure but with empty files will restore the exe

In my larger project where I'm using typescript, then run nexe in the dist folder containing the regular js files, I have also found that the modules I've created and import using require("./foo/bar"), are usually not included in the project. But if I specifically include them using nexe . -r "**/*", they will be included and the exe does run when moved if the empty files are once again added to the test folder.

npm packages

  • If you require and npm installed packages, then copy your node_modules folder next to the moved executable, it will be fixed.
  • I didn't test out my theory using any npm installed modules and clearing their content but I assume if you were to copy the node_modules folder then cleared all files and left them empty, the moved executable will work again

Conclusion

The code is included (even though you might have to include them using the -r) but the executable will still go looking for the files even though it doesn't care about what the content of those files might be.

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

No branches or pull requests

4 participants