cronvel / terminal-kit

Terminal utilities for node.js
MIT License
3.08k stars 198 forks source link

Can't run after packed with pkg #228

Open bcmRayCrazy-coder opened 1 year ago

bcmRayCrazy-coder commented 1 year ago

I just packed my code directly using pkg But I can't launch it, 艹 Error below:

node:internal/modules/cjs/loader:933
  const err = new Error(message);
              ^

Error: Cannot find module './termconfig/xterm.generic.js'
Require stack:
- /snapshot/fr/node_modules/terminal-kit/lib/Terminal.js
- /snapshot/fr/node_modules/terminal-kit/lib/termkit.js
- /snapshot/fr/dist/main.js
- /snapshot/fr/entry.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:1955:46)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at Module.require (pkg/prelude/bootstrap.js:1855:31)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.createTerminal (/snapshot/fr/node_modules/terminal-kit/lib/Terminal.js:161:18)
    at Object.getDetectedTerminal (/snapshot/fr/node_modules/terminal-kit/lib/detectTerminal.js:354:22)
    at /snapshot/fr/dist/main.js
    at new Promise (<anonymous>) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/snapshot/fr/node_modules/terminal-kit/lib/Terminal.js',
    '/snapshot/fr/node_modules/terminal-kit/lib/termkit.js',
    '/snapshot/fr/dist/main.js',
    '/snapshot/fr/entry.js'
  ],
  pkg: true
}
whalemare commented 1 year ago

Same issue. Building with nx and @nrwl/esbuild:esbuild

whalemare commented 1 year ago

@bcmRayCrazy-coder I think I realize.

You need to say to your bundler that this library in using local imports and it should be external. In esbuild I have this option. Rollup have this option too, maybe it can help in your case.

My config for nx.dev

{
// ...
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nrwl/esbuild:esbuild",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/apps/react-native-deploy",
        "format": ["cjs"],
        "main": "apps/react-native-deploy/src/main.ts",
        "tsConfig": "apps/react-native-deploy/tsconfig.app.json",
        "assets": [
          "apps/react-native-deploy/src/assets"
        ],

        // >>>>>>> this lines below for you
        "external": [
          "terminal-kit"
        ]

      }
    },
   // ....
}
WilliamRelken commented 11 months ago

I am experiencing the same issue packaging terminal kit. I reached the same error after setting --external:terminal-kit in esbuild.