-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve cjs deps as cjs instead of esm (#362)
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`. --------- Co-authored-by: Steven <steven@ceriously.com>
- Loading branch information
Showing
5 changed files
with
28 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createRequire } from 'node:module'; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
||
// this will load the CJS export and should not be treated as ESM | ||
const ec = require('@vercel/edge-config'); | ||
|
||
// this will cause the file to be treated as ESM | ||
export default function foo() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters