René's URL Explorer Experiment


Title: `--check` silently passes a `.js` file with a syntax error when the file contains ESM syntax · Issue #65202 · nodejs/node · GitHub

Open Graph Title: `--check` silently passes a `.js` file with a syntax error when the file contains ESM syntax · Issue #65202 · nodejs/node

X Title: `--check` silently passes a `.js` file with a syntax error when the file contains ESM syntax · Issue #65202 · nodejs/node

Description: Version v22.22.1 Platform Microsoft Windows NT 10.0.26200.0 x64 Subsystem module / cli (lib/internal/main/check_syntax.js) What steps will reproduce the bug? Create broken.js in a directory with no package.json: import fs from "node:fs";...

Open Graph Description: Version v22.22.1 Platform Microsoft Windows NT 10.0.26200.0 x64 Subsystem module / cli (lib/internal/main/check_syntax.js) What steps will reproduce the bug? Create broken.js in a directory with no...

X Description: Version v22.22.1 Platform Microsoft Windows NT 10.0.26200.0 x64 Subsystem module / cli (lib/internal/main/check_syntax.js) What steps will reproduce the bug? Create broken.js in a directory with no...

Opengraph URL: https://github.com/nodejs/node/issues/65202

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`--check` silently passes a `.js` file with a syntax error when the file contains ESM syntax","articleBody":"### Version\n\nv22.22.1\n\n### Platform\n\n```text\nMicrosoft Windows NT 10.0.26200.0 x64\n```\n\n### Subsystem\n\nmodule / cli (`lib/internal/main/check_syntax.js`)\n\n### What steps will reproduce the bug?\n\nCreate `broken.js` in a directory with no `package.json`:\n\n```js\nimport fs from \"node:fs\";\nvar = ;\n```\n\nThen:\n\n```console\n$ node --check broken.js ; echo \"exit: $?\"\nexit: 0\n\n$ node broken.js\nvar = ;\n    ^\nSyntaxError: Unexpected token '='\n```\n\n`--check` reports nothing and exits 0 for a file that is not valid JavaScript under either goal\nsymbol.\n\n### How often does it reproduce? Is there a required condition?\n\nAlways, given the condition: the file's format must be **ambiguous** — a `.js` extension with no\n`\"type\"` in the nearest `package.json` — and the source must contain `import` or `export`.\nEverything that states its format is handled correctly:\n\n| the file | `node --check` |\n| --- | --- |\n| `.mjs`, or `\"type\": \"module\"` | correct — reports the error |\n| `\"type\": \"commonjs\"` | correct — `Cannot use import statement outside a module` |\n| **`.js`, no `\"type\"`, containing `import`/`export`** | **exit 0, nothing reported** |\n| `.js` whose only ESM signal is top-level `await` | correct — reports the error |\n\n### What is the expected behavior? Why is that the expected behavior?\n\nA non-zero exit and the `SyntaxError`, as with every other invalid file. The documentation for\n`-c`, `--check` is \"Syntax check the script without executing\", with no caveat about module\ndetection — and the same source reports the error correctly the moment its format is stated.\n\nThis matters in practice because `node --check` is a common cheap gate in CI, and a plain `.js`\nfile containing `import` is the shape most projects have — so the sources most likely to be\nchecked are the ones that silently pass.\n\n### What do you see instead?\n\nExit code 0 and no output.\n\n### Additional information\n\n`lib/internal/main/check_syntax.js` parses under the Module goal only when `defaultGetFormat`\nanswers `'module'`, which an ambiguous `.js` does not:\n\n```js\nif (format === 'module') {\n  const { ModuleWrap } = internalBinding('module_wrap');\n  new ModuleWrap(filename, undefined, source, 0, 0);\n  return;\n}\n\nwrapSafe(filename, source, undefined, format);\n```\n\nSo the CommonJS branch runs. Inside `wrapSafe`, `cjsModuleInstance` is `undefined` here, so\n`shouldDetectModule` falls through to `--require-module` — on by default — and\n`compileFunctionForCJSLoader` *detects* ESM instead of throwing. Its result is then discarded, and\nthe source is never parsed under either goal.\n\n`Module.prototype._compile` handles exactly this case correctly a little further down the same\nfile, by reading the flag the detection returns:\n\n```js\nif (format !== 'module') {\n  const result = wrapSafe(filename, content, this, format);\n  compiledWrapper = result.function;\n  if (result.canParseAsESM) {\n    format = 'module';\n  }\n}\n\nif (format === 'module') {\n  loadESMFromCJS(this, filename, format, content);\n  return;\n}\n```\n\n`checkSyntax` looks like it wants the same `canParseAsESM` branch, falling back to the `ModuleWrap`\nparse it already has above rather than returning.\n\nThe relevant part of `check_syntax.js` is unchanged on `main`; the file was last touched\n2024-12-02. The behaviour most likely dates from `module: unflag detect-module` (2024-07-20), which\nmade detection the default for this path.\n\n**Test coverage.** `test/sequential/test-cli-syntax-bad.js` checks `bad_syntax.js`, `bad_syntax`,\n`bad_syntax_shebang.js` and `bad_syntax_shebang` — all CommonJS.\n`test/fixtures/syntax/bad_syntax.mjs` exists but is used only by `test-esm-error-cache.js` and\n`test-compile-cache-bad-syntax.js`, not by either `--check` test. So neither a `.mjs` file nor a\ndetected-ESM `.js` file is currently asserted to fail `--check`.\n\nI am happy to open a PR with the fix and a fixture plus test if that shape is welcome.\n\n\u003csub>Found while differential-testing Node against\n[ViperJS](https://github.com/MerlijnW70/viperjs), an embeddable JavaScript engine in safe Rust.\nSweeping eight repositories, the two disagreed about 18 files; every one of them turned out to be\ngenuinely invalid JavaScript, and `node --check` had reported nine as fine. V8 itself is right\nabout all eighteen — it is only `--check` that never asks it.\u003c/sub>\n","author":{"url":"https://github.com/MerlijnW70","@type":"Person","name":"MerlijnW70"},"datePublished":"2026-08-10T20:55:10Z","url":"https://github.com/nodejs/node/issues/65202"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0c725ef8-d502-d0ed-5140-d90d7a273369
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9AD2:1F5F5F:11C5408:1799F55:6AED58BB
html-safe-noncec73461e3454981b8fb8d458ae0edee6622f41b0c368393721dc9eb8099a3156c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QUQyOjFGNUY1RjoxMUM1NDA4OjE3OTlGNTU6NkFFRDU4QkIiLCJ2aXNpdG9yX2lkIjoiNTc4Mzg0MzM0NzYxMjEyOTQ2NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac8b73785844d76a8800dcd9a246bbf83a0240926cabd0472b0362d7bde36f2947
hovercard-subject-tagissue:5114279303
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/65202/issue_layout
twitter:imagehttps://opengraph.githubassets.com/051ea5bdccb497f1b414841042c7514efbb4b4e664d0ec68af43e2f2fd07ced3/nodejs/node/issues/65202
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/051ea5bdccb497f1b414841042c7514efbb4b4e664d0ec68af43e2f2fd07ced3/nodejs/node/issues/65202
og:image:altVersion v22.22.1 Platform Microsoft Windows NT 10.0.26200.0 x64 Subsystem module / cli (lib/internal/main/check_syntax.js) What steps will reproduce the bug? Create broken.js in a directory with no...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameMerlijnW70
hostnamegithub.com
expected-hostnamegithub.com
None56fb42677ae87ed3e64410323d67980aa65d0485568a7858f874e7edfc6d1c11
turbo-cache-controlno-preview
go-importgithub.com/nodejs/node git https://github.com/nodejs/node.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id27193779
octolytics-dimension-repository_nwonodejs/node
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id27193779
octolytics-dimension-repository_network_root_nwonodejs/node
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9c9a37e2423ed382cf39f70b5aa4b4858b40a3b0
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/nodejs/node/issues/65202#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F65202
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F65202
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=nodejs%2Fnode
Reloadhttps://github.com/nodejs/node/issues/65202
Reloadhttps://github.com/nodejs/node/issues/65202
Reloadhttps://github.com/nodejs/node/issues/65202
nodejshttps://github.com/nodejs
nodehttps://github.com/nodejs/node
Codehttps://github.com/nodejs/node
Issues654 (654)https://github.com/nodejs/node/issues
Pull requests662 (662)https://github.com/nodejs/node/pulls
Actionshttps://github.com/nodejs/node/actions
Projectshttps://github.com/nodejs/node/projects
Security and qualityhttps://github.com/nodejs/node/security
Insightshttps://github.com/nodejs/node/pulse
https://github.com/nodejs/node
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/65202
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/65202
#65203https://github.com/nodejs/node/pull/65203
--check silently passes a .js file with a syntax error when the file contains ESM syntaxhttps://github.com/nodejs/node/issues/65202#top
#65203https://github.com/nodejs/node/pull/65203
https://github.com/MerlijnW70
MerlijnW70https://github.com/MerlijnW70
on Aug 10, 2026https://github.com/nodejs/node/issues/65202#issue-5114279303
ViperJShttps://github.com/MerlijnW70/viperjs
https://github.com/bitpshr
bitpshrhttps://github.com/bitpshr
on Aug 10, 2026https://github.com/nodejs/node/issues/65202#issuecomment-5246127103
#65203https://github.com/nodejs/node/pull/65203
nodejs-github-bothttps://github.com/nodejs-github-bot
completedhttps://github.com/nodejs/node/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#65203https://github.com/nodejs/node/pull/65203
on Aug 12, 2026https://github.com/nodejs/node/issues/65202#event-29367540601
nodejs-github-bothttps://github.com/nodejs-github-bot
on Aug 12, 2026https://github.com/nodejs/node/issues/65202#event-29367540658
module: fix --check on ambiguous ESM fileshttps://github.com/nodejs/node/commit/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e
1b2de5ehttps://github.com/nodejs/node/commit/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e
aduh95https://github.com/aduh95
on Aug 13, 2026https://github.com/nodejs/node/issues/65202#event-29399905713
module: fix --check on ambiguous ESM fileshttps://github.com/nodejs/node/commit/e98731e9439a867bcf0deb2395f424c2ae0a4661
e98731ehttps://github.com/nodejs/node/commit/e98731e9439a867bcf0deb2395f424c2ae0a4661
aduh95https://github.com/aduh95
on Aug 25, 2026https://github.com/nodejs/node/issues/65202#event-30010539965
module: fix --check on ambiguous ESM fileshttps://github.com/nodejs/node/commit/d7805e00dc7043f439e943ca5132244751fa3ba9
d7805e0https://github.com/nodejs/node/commit/d7805e00dc7043f439e943ca5132244751fa3ba9
module: fix --check on ambiguous ESM fileshttps://github.com/nodejs/node/commit/961bd04370a4a6b4b6d82fa15896b50d1765509a
961bd04https://github.com/nodejs/node/commit/961bd04370a4a6b4b6d82fa15896b50d1765509a
Sign up for freehttps://github.com/signup?return_to=https://github.com/nodejs/node/issues/65202
Sign in to commenthttps://github.com/login?return_to=https://github.com/nodejs/node/issues/65202
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.