vercel / nft

Node.js dependency tracing utility
https://npmjs.com/@vercel/nft
MIT License
1.31k stars 136 forks source link

Does not include registered ESM loader hooks #428

Closed timfish closed 1 month ago

timfish commented 3 months ago

package.json

{
  "type": "module",
  "dependencies": {
    "import-in-the-middle": "^1.8.1"
  },
  "devDependencies": {
    "@vercel/nft": "^0.27.2"
  }
}

test.js

import { register } from 'module';

register('import-in-the-middle/hook.mjs', import.meta.url);

build.js

import { nodeFileTrace } from '@vercel/nft';
const { fileList } = await nodeFileTrace(['./test.js']);
console.log(fileList)

Running > node build.js Outputs Set(1) { 'test.js' }

But import-in-the-middle/hook.mjs and all of it's dependencies should be included.

s1gr1d commented 1 month ago

This also affects nitropack (and therefore also Nuxt). The .output build folder of nuxt does not include import-in-the-middle/hook.mjs which can lead to the same error.

I am not a 100% sure how nuxt builds nuxt apps under the hood but nodeFileTrace is used here in nitropack: https://github.com/unjs/nitro/blob/v2/src/rollup/plugins/externals.ts

@pi0 @vercel/nft should probably be updated after this is merged: https://github.com/vercel/nft/pull/429

pi0 commented 1 month ago

Thanks for the heads up @s1gr1d. Nitro has a caret ^ dependency on @vercel/nft which means as long as any fix or enhancement lands in a semver-minor/patch version of this package, updating your lock file is enough to get the fix.

Nevertheless feel free to report an issue downstream in nitropack repo if you can assemble a minimal nitro reproduction 🙏🏼

github-actions[bot] commented 1 month ago

:tada: This issue has been resolved in version 0.27.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket: