cronvel / terminal-kit

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

Unable to bundle code with dependencies #243

Open KevinKWZheng opened 6 months ago

KevinKWZheng commented 6 months ago

I can properly bundle my code before using this module with Rollup, but now after it is bundled, it gives an error:

Error: Could not dynamically require "./termconfig/xterm.generic.js". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.

I tried setting dynamicRequireTargets to ./termconfig/xterm.generic.js, but this does not solve the problem

cronvel commented 6 months ago

Before what? After what?

KevinKWZheng commented 6 months ago

I meant that before I introduce this module into my project, the bundled code could directly by ran by passing in 'node' command. Now it would give the error above

cronvel commented 6 months ago

I'm guessing that you want to use it inside a browser with a terminal emulator.

You have to use ./lib/browser.js as the entry point for your bundler. You may have to add manually some files to your bundler. Also due to the nature of Terminal-Kit, it was not meant to be browser-friendly, so good luck.

KevinKWZheng commented 6 months ago

Actually, no. I am creating a Node command line app. I am trying to use Node 21's single executable file function, so I would need to bundle all my code including external modules into a single file so that I can then compile it.

cronvel commented 6 months ago

Ok, so you need to include all source file manually. I use extensively lazy-loading, since there is a lot of files, and I like my CLI to start as fast as possible, so all the specific terminal config are not loaded unless used, as well as various rarely used features.

You can use ./lib/termkit-no-lazy-require.js as the entry point, however terminal configs are still loaded dynamicly. So you should add manually everything contained inside the ./lib/termconfig/ folder.