vercel / nft

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

fix: resolve cjs deps as cjs instead of esm #362

Closed cb1kenobi closed 1 year ago

cb1kenobi commented 1 year ago

When nft analyzes a file that has both a require() and an ESM export, the first call to acorn fails because of the export, so it treats the whole file as ESM, which is probably fine.

The problem is it treats the require() as an ESM import which is wrong. This will cause the resolve dependency entrypoint in the dependency to get the ESM export instead of the proper CJS export.

If the dependency is an import, add it to imports. If it's a require(), add it to deps and don't worry about whatever isESM.

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 0.24.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: