vercel / ncc

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

TypeError when resolving symlinked module paths in a Lerna workspace #1184

Open lamjack opened 2 months ago

lamjack commented 2 months ago

I am encountering a TypeError: Cannot read properties of undefined (reading 'uid') when using ncc in a project managed with Lerna's workspaces where module paths are symlinked. Below are the details of the error and the context in which it occurs:

TypeError: Cannot read properties of undefined (reading 'uid')
    at Object.statSync (/Users/jack/Dev/zeus/@zeusjs/node_modules/.pnpm/@vercel+ncc@0.33.3/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:1:563316)
    at isDirectory (/Users/jack/Dev/zeus/@zeusjs/node_modules/.pnpm/resolve@1.22.8/node_modules/resolve/lib/sync.js:31:23)
    at loadNodeModulesSync (/Users/jack/Dev/zeus/@zeusjs/node_modules/.pnpm/resolve@1.22.8/node_modules/resolve/lib/sync.js:200:17)
    at Function.resolveSync [as sync] (/Users/jack/Dev/zeus/@zeusjs/node_modules/.pnpm/resolve@1.22.8/node_modules/resolve/lib/sync.js:107:17)
    at buildDep (/Users/jack/Dev/zeus/@zeusjs/scripts/bundleDeps.ts:28:21)
    at <anonymous> (/Users/jack/Dev/zeus/@zeusjs/scripts/bundleDeps.ts:348:11)
    at resolve (/Users/jack/Dev/zeus/@zeusjs/scripts/bundleDeps.ts:361:1)
    at Object.<anonymous> (/Users/jack/Dev/zeus/@zeusjs/scripts/bundleDeps.ts:361:4)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Object.j (/Users/jack/Dev/zeus/@zeusjs/node_modules/.pnpm/tsx@3.14.0/node_modules/tsx/dist/cjs/index.cjs:1:1197)

my source code:

let { code, assets } = await ncc(entry, {
    externals: opts.webpackExternals,
    minify: !!opts.minify,
    target: 'es2015',
    assetBuilds: false,
    cache: false,
    debugLog: true
});

I have confirmed using ls that the entry path exists and is a symlink, which is typical in a Lerna workspace environment. This seems to cause an issue with path resolution or stat operations in ncc. I am wondering if ncc has known limitations or issues with handling symlinked paths that might lead to such errors.

Any advice on how to work around this issue or any plans for future updates that might address this problem would be greatly appreciated.

Thank you for your assistance and for the great tool!