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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node_modules unclear behaviour #1093

Open
glani opened this issue Apr 26, 2024 · 0 comments
Open

node_modules unclear behaviour #1093

glani opened this issue Apr 26, 2024 · 0 comments
Labels

Comments

@glani
Copy link

glani commented Apr 26, 2024

What happened:
It is still unclear how to bundle node_modules inside executable. Checking code of nexe shows that there is VirtualFS implementation. However, a packed application points to the file system and is looking in current folder for node_modules folder

What you expected to happen:
Is there a way to use node_modules from packed executable in case of attaching the folder via --resource node_modules ?

the correct behaviour with node_modules in the same folder where exe sits:

heelo
/app/logs/w-gen.log
Hello World

instead of

root@e5dde1e2895e:/app# /tmp/test-cli
heelo
/app/logs/w-gen.log
Hello World
node:events:496
throw er; // Unhandled 'error' event
^

Error: ENOENT: no such file or directory, open '/tmp/node_modules/pino/lib/worker.js'
at Object.openSync (node:fs:582:18)
at Object.readFileSync (node:fs:461:35)
at readFileSync (/tmp/datahub-cli:233:55)
at getSourceSync (node:internal/modules/esm/load:85:14)
at getSource (node:internal/modules/esm/translators:72:10)
at createCJSModuleWrap (node:internal/modules/esm/translators:300:32)
at ModuleLoader.commonjsStrategy (node:internal/modules/esm/translators:379:10)
at async link (node:internal/modules/esm/module_job:78:21)
Emitted 'error' event on ThreadStream instance at:
at Immediate. (/tmp/node_modules/thread-stream/index.js:369:12)
at process.processImmediate (node:internal/timers:478:21)

Node.js v20.12.2
How to reproduce it (as minimally and precisely as possible):

package.json

{
  "name": "test-cli",
  "private": true,
  "version": "0.0.1",
  "description": "test-cli application",
  "type": "commonjs",
  "dependencies": {
    "pino-pretty": "^11.0.0",
    "pino": "^9.0.0",
    "thread-stream": "^2.7.0"
  }
}

main.js

var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// apps/datahub-cli/src/main.ts
var main_exports = {};
__export(main_exports, {
  logger: () => logger
});
module.exports = __toCommonJS(main_exports);

// apps/datahub-cli/src/logic/upload.ts
var Upload = class {
  constructor() {
  }
  sayHello() {
    return "heelo";
  }
};

// apps/datahub-cli/src/main.ts
var pino = __toESM(require("pino"));
var path = __toESM(require("path"));
var defaultOpts = {
  singleLine: true,
  mkdir: true,
  hideObject: false,
  ignore: "hostname",
  prettyPrint: true
};
var targets = buildTransport();
var logger = pino.pino({
  browser: {
    asObject: true
  },
  transport: {
    targets
  },
  serializers: {},
  level: "debug"
  // timestamp: pino.stdTimeFunctions.isoTime,
});
function buildTransport() {
  const enableConsoleLog = true;
  const logFolder = "logs";
  const logLevel = "debug";
  const pinoPretty = {
    target: "pino-pretty",
    options: {
      timestampKey: "time",
      singleLine: true,
      hideObject: false,
      ignore: "hostname"
    },
    level: logLevel
  };
  const targets2 = [
    {
      level: logLevel,
      target: "pino/file",
      options: {
        ...defaultOpts,
        destination: path.resolve(logFolder, "w-gen.log")
      }
    }
  ];
  if (enableConsoleLog) {
  }
  return targets2;
}
logger.info("sdfsdf");
var upload = new Upload();
console.log(upload.sayHello());
console.log(path.resolve("logs", "w-gen.log"));
console.log("Hello World");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  logger
});

Anything else we need to know?:

Environment:

  • Platform(OS/Version):

macos 14 arm and "Debian GNU/Linux 10 (buster)"

  • Host Node Version:
    v20.12.x also tried with v16.20.2
  • Target Node Version: the same as host
  • Nexe version: 4.0.0-rc.4
  • Python Version: Python 3.7.3

command to build:

npx nexe ./main.js --cwd=. --resource "./node_modules/**/*" -o datahub-cli --build=true --python=$(which python3) --verbose --logLevel=debug

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

No branches or pull requests

1 participant