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.26k stars 288 forks source link

Lazy imports fail to be compiled #495

Open mrmckeb opened 4 years ago

mrmckeb commented 4 years ago

I was compiling a CLI with update-notifier.

However, they're lazy importing - which results in packages being missed when compiling.

Their code looks like this:

const importLazy = require('import-lazy')(require);

const isCi = importLazy('is-ci');

The compiled code expects is-ci to be a dependency.

Here's a related issue someone raised with them: https://github.com/yeoman/update-notifier/issues/123.

PS: This is a great package.

iansu commented 4 years ago

I just ran into this same issue (hi @mrmckeb :wave:). I worked around this by making update-notifier a dependency and then excluding it from compilation by ncc. This works but isn't ideal since the CLI now has some dependencies that need to be installed along with it.

mrmckeb commented 4 years ago

Thanks @iansu - I ended up doing the same thing! It works, and will do as a temporary fix ;)

cxspxr commented 4 years ago

Hi, I created a fork for that matter because seems like this will never be supported

https://github.com/datacrafts-io/update-notifier-webpack https://www.npmjs.com/package/update-notifier-webpack

Also, my fork should be always up-to-date thanks to https://github.com/wei/pull bot that will track original package for any updates.

TooTallNate commented 4 years ago

Seems that update-notifier-webpack still doesn't work with ncc since the check.js file attempts to require update-notifier-webpack (require('.')) which ends up requiring the CLI code in the dist dir, rather than the updater package.

cxspxr commented 4 years ago

Oh, I see now.