Giter VIP home page Giter VIP logo

Comments (3)

NotMikeDEV avatar NotMikeDEV commented on June 10, 2024 1

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.

from nexe.

DeRidderJonas avatar DeRidderJonas commented on June 10, 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 [email protected]

@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.

from nexe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.