nexe/nexe

Error: Cannot find module 'node:util'

ringo360 opened this issue · 5 comments

What happened:

I created exe file using nexe index.js --target windows-x64-14.15.3. but when I run it, I get the following error:

internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'node:util'
Require stack:
- C:\Users\GPTP3\GitHub\test-uwu\node_modules\consola\dist\shared\consola.deac7d5a.cjs
- C:\Users\GPTP3\GitHub\test-uwu\node_modules\consola\dist\shared\consola.4bbae468.cjs
- C:\Users\GPTP3\GitHub\test-uwu\node_modules\consola\dist\index.cjs
- C:\Users\GPTP3\GitHub\test-uwu\node_modules\consola\lib\index.cjs
- C:\Users\GPTP3\GitHub\test-uwu\src\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\Users\GPTP3\GitHub\test-uwu\node_modules\consola\dist\shared\consola.deac7d5a.cjs:3:19)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\GPTP3\\GitHub\\test-uwu\\node_modules\\consola\\dist\\shared\\consola.deac7d5a.cjs',
    'C:\\Users\\GPTP3\\GitHub\\test-uwu\\node_modules\\consola\\dist\\shared\\consola.4bbae468.cjs',
    'C:\\Users\\GPTP3\\GitHub\\test-uwu\\node_modules\\consola\\dist\\index.cjs',
    'C:\\Users\\GPTP3\\GitHub\\test-uwu\\node_modules\\consola\\lib\\index.cjs',
    'C:\\Users\\GPTP3\\GitHub\\test-uwu\\src\\index.js'
  ]
}

What you expected to happen:
Everything must work perfectly

How to reproduce it (as minimally and precisely as possible):

  1. Write code:
//index.ts
import { consola } from 'consola';

async function main() {
	let urname = await consola.prompt('What is your name?', {
		placeholder: 'John',
	});
	if (!urname) urname = 'John';
	consola.box(`Hello, ${urname}!`);
}

consola.info(`Hello Sekai!`);
main();
  1. do tsc index.ts
  2. do nexe index.js --target windows-x64-14.15.3
  3. open generated exe file
  4. you can see error log

Anything else we need to know?:

nothing

Environment:

  • Platform(OS/Version): Windows 11 (AtlasOS v0.4.0)
  • Host Node Version: v21.2.0
  • Target Node Version: v21.2.0
  • Nexe version: 4.0.0-rc.6
  • Python Version: Not installed

Hello, i have the same issue, Error: Cannot find module 'node:util' but with another library: .\node_modules\sharp\lib\constructor.js

Have you found any solution yet?

Nah, I can't find any solution 😢
Probably, consola depends on node:utils.

@ringo360

The source code needs to be bundled, including its dependencies, into a single JavaScript file.

Example by esbuild:

esbuild index.ts --bundle --minify --platform=node --target=node14.17.0 --outdir=dist
nexe dist/index.js --target windows-x64-14.15.3

Thanks, I'll try that!

It works! thank you @mikoto2000 🩵