Title: detect-module: confusing error when parsing a CommonJS module with top-level `await` · Issue #55776 · nodejs/node · GitHub
Open Graph Title: detect-module: confusing error when parsing a CommonJS module with top-level `await` · Issue #55776 · nodejs/node
X Title: detect-module: confusing error when parsing a CommonJS module with top-level `await` · Issue #55776 · nodejs/node
Description: Porting from nodejs/TSC#1445 (comment): index.js: const { getPort, checkPort, getRandomPort, waitForPort, } = require("get-port-please") const port = await getPort() Getting this: Restarting 'index.js' (node:15356) [MODULE_TYPELESS_PACKA...
Open Graph Description: Porting from nodejs/TSC#1445 (comment): index.js: const { getPort, checkPort, getRandomPort, waitForPort, } = require("get-port-please") const port = await getPort() Getting this: Restarting 'index...
X Description: Porting from nodejs/TSC#1445 (comment): index.js: const { getPort, checkPort, getRandomPort, waitForPort, } = require("get-port-please") const port = await getPort() Getting this: Restart...
Opengraph URL: https://github.com/nodejs/node/issues/55776
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"detect-module: confusing error when parsing a CommonJS module with top-level `await`","articleBody":"Porting from https://github.com/nodejs/TSC/issues/1445#issuecomment-2388678002:\r\n\r\n`index.js`:\r\n\r\n```js\r\nconst {\r\n getPort,\r\n checkPort,\r\n getRandomPort,\r\n waitForPort,\r\n} = require(\"get-port-please\")\r\n\r\nconst port = await getPort()\r\n```\r\n\r\nGetting this:\r\n\r\n```\r\nRestarting 'index.js'\r\n(node:15356) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///C:/Users/Babak/Documents/Code/c12/index.js is not specified and it doesn't parse as CommonJS.\r\nReparsing as ES module because module syntax was detected. This incurs a performance overhead.\r\nTo eliminate this warning, add \"type\": \"module\" to C:\\Users\\Babak\\Documents\\Code\\c12\\package.json.\r\n(Use `node --trace-warnings ...` to show where the warning was created)\r\nfile:///C:/Users/Babak/Documents/Code/c12/index.js:7\r\n} = require(\"get-port-please\")\r\n ^\r\n\r\nReferenceError: require is not defined in ES module scope, you can use import instead\r\n at file:///C:/Users/Babak/Documents/Code/c12/index.js:7:5\r\n at ModuleJob.run (node:internal/modules/esm/module_job:262:25)\r\n at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:483:26)\r\n\r\nNode.js v22.9.0\r\nFailed running 'index.js'\r\n```\r\n\r\nWith this `package.json`:\r\n\r\n```json\r\n{\r\n \"dependencies\": {\r\n \"express\": \"4.21.0\",\r\n \"get-port-please\": \"3.1.2\"\r\n },\r\n \"devDependencies\": {\r\n \"@types/express\": \"5.0.0\"\r\n }\r\n}\r\n```\r\n\r\nLOL. (`await` 😈).\r\n\r\n_Originally posted by @babakfp in https://github.com/nodejs/TSC/issues/1445#issuecomment-2388678002_\r\n\r\n\u003chr\u003e\r\n\r\nSo basically, this module fails to parse as _either_ CommonJS or as ESM, and we show the ESM parsing error message. Perhaps we should show both, or show a special message for the common use case of using top-level `await` in a CommonJS module.","author":{"url":"https://github.com/GeoffreyBooth","@type":"Person","name":"GeoffreyBooth"},"datePublished":"2024-11-08T10:59:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/55776/node/issues/55776"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:285f8ab6-d8d6-391e-c7a5-59ccddc5c5de |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A302:247EB:5A91F7:79FC01:6A4D3EBB |
| html-safe-nonce | 756805238ea7896ccda6544c7ab8c74dc135325b772268d85c57e640de1d7636 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzAyOjI0N0VCOjVBOTFGNzo3OUZDMDE6NkE0RDNFQkIiLCJ2aXNpdG9yX2lkIjoiMTQ4ODM0NDQ2MzQ5OTQxMTEzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1097a2bd45aeb386c99596b105787712ab702f17c75900f05bb2885ad4237029 |
| hovercard-subject-tag | issue:2643681005 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/nodejs/node/55776/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ec4a92d785ddd55e6f0c7e8b9e3df59fae141648694ec68bf5d82c0091b1fbf6/nodejs/node/issues/55776 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ec4a92d785ddd55e6f0c7e8b9e3df59fae141648694ec68bf5d82c0091b1fbf6/nodejs/node/issues/55776 |
| og:image:alt | Porting from nodejs/TSC#1445 (comment): index.js: const { getPort, checkPort, getRandomPort, waitForPort, } = require("get-port-please") const port = await getPort() Getting this: Restarting 'index... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | GeoffreyBooth |
| hostname | github.com |
| expected-hostname | github.com |
| None | 92571a8944142227b7e19cd10918b1ddd06e5066c1ad5bc7e4769cf6140a87e6 |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 56fc8347865a14e2ec811533d68f929cf4e0ec19 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width