vercel / ncc

Compile a Node.js project into a single file. Supports TypeScript, binary addons, dynamic requires.
https://npmjs.com/@vercel/ncc
MIT License
9.27k stars 291 forks source link

NCCing a project that uses ktor results in not found modules #1221

Closed Vampire closed 3 weeks ago

Vampire commented 3 weeks ago

I have a Kotlin/JS project that uses ncc on the compile result to pack the result together for usage as GitHub Action. Now I added ktor client as a dependency. This has three eval('require')('some-module') calls in the JavaScript. (Don't ask me why, I don't know, this also makes it incompatible to ESM. But the end-result is, that if you try to run the ncc-packed code, you get missing modules errors for those when the code is hit.

styfle commented 3 weeks ago

This is expected. Usually eval is used to intentionally avoid static analysis tools like ncc.

Vampire commented 3 weeks ago

Not in this case I think. Here it is more to due to the polyfill hack it is I think. If I preprocess the compile result by replacing eval('require')( by require( before sending it through ncc, that allows it to pack properly and it seems to work so far. :-)

Vampire commented 3 weeks ago

Would there be another work-around possible like telling ncc to bring over those modules or something like that?

styfle commented 3 weeks ago

No other workarounds at this time. If you fix the code to use require(), it should work as expected.