Title: [25.x] module: fix extensionless CJS files in type:module packages by mcollina · Pull Request #62083 · nodejs/node · GitHub
Open Graph Title: [25.x] module: fix extensionless CJS files in type:module packages by mcollina · Pull Request #62083 · nodejs/node
X Title: [25.x] module: fix extensionless CJS files in type:module packages by mcollina · Pull Request #62083 · nodejs/node
Description: PR #61600 made the CJS loader respect the `package.json` `type` field for extensionless files, which fixed #61104 but also enforced `type: "module"` for extensionless files. This broke CJS extensionless files inside ESM packages (e.g. yargs v17). Only enforce `type: "commonjs"` for extensionless files. For `type: "module"`, leave format undefined so syntax detection handles it. This restores the documented exception in the CJS documentation that has existed since v16: when the nearest parent `package.json` file contains a top-level field `"type"` with a value of `"module"`, those files will be recognized as CommonJS modules only if they are being included via `require()`, not when used as the command-line entry point of the program This PR is targeted at `v25.x-staging` only. On `main` (v26), #61600 stays as-is and the exception should be removed from the CJS documentation in a separate PR to align the docs with the ESM resolution specification. Fixes: #61971 Refs: yargs/yargs#2509 Refs: #61600
Open Graph Description: PR #61600 made the CJS loader respect the `package.json` `type` field for extensionless files, which fixed #61104 but also enforced `type: "module"` for extensionless files. This broke CJ...
X Description: PR #61600 made the CJS loader respect the `package.json` `type` field for extensionless files, which fixed #61104 but also enforced `type: "module"` for extensionless files. This ...
Opengraph URL: https://github.com/nodejs/node/pull/62083
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:66aced7d-0676-97a8-e95b-dba1d4e17ab1 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8A24:354A24:3C11D1:4F5235:6A4C3FDF |
| html-safe-nonce | ff5f9f22a112665fe48a0dafd4735641a9b84b68574cf0abf6a748db777732d3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTI0OjM1NEEyNDozQzExRDE6NEY1MjM1OjZBNEMzRkRGIiwidmlzaXRvcl9pZCI6Ijc5NTkwNTQxMzE5Mzg0NzU5OTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a8f25f2fabbab94bec83fabdfdb0301387781eba28fa765a996bb5f7f1fd9e93 |
| hovercard-subject-tag | pull_request:3348120510 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/nodejs/node/pull/62083/files |
| twitter:image | https://avatars.githubusercontent.com/u/52195?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/52195?s=400&v=4 |
| og:image:alt | PR #61600 made the CJS loader respect the `package.json` `type` field for extensionless files, which fixed #61104 but also enforced `type: "module"` for extensionless files. This broke CJ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3996b3b83990e134be6c099ab9a7f48f140ae80f |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width