Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Failing to build with terminal-kit due to non-literal require calls #1619

Closed
djkato opened this issue May 5, 2022 · 3 comments
Closed

Failing to build with terminal-kit due to non-literal require calls #1619

djkato opened this issue May 5, 2022 · 3 comments
Labels

Comments

@djkato
Copy link

djkato commented May 5, 2022

What version of pkg are you using?

5.5.2

What version of Node.js are you using?

16.14.0

What operating system are you using?

Windows

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

latest-win-x64, latest-macos-x64, latest-linux-x64

Describe the Bug

Hello, I'm trying to build a project made with terminal-kit for all platforms, but I can't get it to build I think due to non-literal require calls. It builds without errors, but running it throws this error:

pkg/prelude/bootstrap.js:1833
      throw error;
      ^

Error: Cannot find module './termconfig/xterm.generic.js'
Require stack:
- \node_modules\terminal-kit\lib\Terminal.js
- \node_modules\terminal-kit\lib\termkit.js
- \bin\index.js
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function._resolveFilename (pkg/prelude/bootstrap.js:1912:46)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at Module.require (pkg/prelude/bootstrap.js:1812:31)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.createTerminal (\node_modules\terminal-kit\lib\Terminal.js:159:18)
    at terminal (\node_modules\terminal-kit\lib\termkit.js:119:18)
    at Object.get [as terminal] (\node_modules\lazyness\lib\Lazyness.js:48:16)
    at Object.<anonymous> (\bin\index.js:8:20) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '\\node_modules\\terminal-kit\\lib\\Terminal.js',
    '\\node_modules\\terminal-kit\\lib\\termkit.js',
    '\\bin\\index.js'
  ],
  pkg: true
}
Node.js v17.8.0

I believe this is the piece of code: Terminal.js from l:138

if (!termconfig) {
  // The real terminal app is not known, or we fail to load it...
  // Fallback to the terminal generic (most of time, got from the $TERM env variable).
  try {
    // If a .generic.js file exists, this is a widely used terminal generic, 'xterm' for example.
    // We should use this generic files because despite advertising them as 'xterm',
    // most terminal sucks at being truly 'xterm' compatible (only 33% to 50% of xterm capabilities
    // are supported, even gnome-terminal and Konsole are bad).
    // So we will try to maintain a fail-safe xterm generic config.
    term.termconfigFile = term.generic + '.generic.js'
    termconfig = require('./termconfig/' + term.termconfigFile)
  }
  catch (error) {
    try {
      // No generic config exists, try a specific config
      term.termconfigFile = term.generic + '.js'
      termconfig = require('./termconfig/' + term.termconfigFile)
    }
    catch (error_) {
      // Nothing found, fallback to the most common terminal generic
      term.termconfigFile = 'xterm.generic.js'
      termconfig = require('./termconfig/' + term.termconfigFile)
      // changing the above line to: termconfig = require('./termconfig/xterm.generic.js') compiles, runs but shows nothing in terminal
    }
  }
}

My package.json:

{
  "name": "x",
  "version": "1.0.1",
  "description": "x",
  "main": "index.js",
  "bin": {
    "8mb": "bin/index.js"
  },
  "scripts": {
    "start": "node bin/index.js",
    "build": "pkg package.json --output dist/8mb",
    "test": "node fieldTest.cjs"
  },
  "keywords": [
    "discord",
    "media",
    "encoder",
    "ffmpeg"
  ],
  "author": "djkato",
  "license": "ISC",
  "dependencies": {
    "cli-progress": "^3.11.0",
    "filehound": "^1.17.6",
    "pkg": "^5.6.0",
    "require-runtime": "^2.0.0",
    "terminal-kit": "^2.4.0"
  },
  "pkg": {
    "scripts": "node_modules/terminal-kit/lib/**/*js",
    "assets": "node_modules/terminal-kit/lib/**/*.json",
    "targets": [
      "latest-win-x64",
      "latest-macos-x64",
      "latest-linux-x64"
    ],
    "outputPath": ""
  }
}

How could I rewrite this to support building? I looked around and saw that this isn't the only non literal require. Or if it isn't necessary, then how could I make it work? Trying the fixes suggested in other similar issues don't seem to work for me, I think I applied them right in my package.json.
Thanks, dj

Similar git issues: nexe/509
pkg/1018
some forum post

Expected Behavior

To build and execute correctly.

To Reproduce

npm init
npm install pkg terminal-kit

test.js:

const termkit = require("terminal-kit")
termkit.terminal("test")

package.json:

{
  "name": "reproduction",
  "version": "1.0.0",
  "description": "",
  "main": "test.js",
  "bin": {
    "8mb": "test.js"
  },
  "scripts": {
    "build": "pkg package.json --output 8mb"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "pkg": "^5.6.0",
    "terminal-kit": "^2.4.0"
  },
  "pkg": {
    "scripts": "node_modules/terminal-kit/lib/**/*.js",
    "assets": "node_modules/terminal-kit/lib/**/*.json",
    "targets": [
      "latest-win-x64",
      "latest-macos-x64",
      "latest-linux-x64"
    ],
    "outputPath": ""
  }
}

npm run build
8mb-win.exe: ERRROR

@djkato
Copy link
Author

djkato commented May 5, 2022

#1018
#nexe/nexe#509

@github-actions
Copy link

github-actions bot commented Aug 4, 2022

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

@github-actions github-actions bot added the Stale label Aug 4, 2022
@github-actions
Copy link

github-actions bot commented Aug 9, 2022

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.

@github-actions github-actions bot closed this as completed Aug 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant