Title: custom Import attributes with esm hooks · Issue #51128 · nodejs/node · GitHub
Open Graph Title: custom Import attributes with esm hooks · Issue #51128 · nodejs/node
X Title: custom Import attributes with esm hooks · Issue #51128 · nodejs/node
Description: Version 20.10 Platform Linux akala 6.2.16-19-pve #1 SMP PREEMPT_DYNAMIC PMX 6.2.16-19 (2023-10-24T12:07Z) x86_64 x86_64 x86_64 GNU/Linux Subsystem esm hooks What steps will reproduce the bug? Setup an ESM hook that handles a specific imp...
Open Graph Description: Version 20.10 Platform Linux akala 6.2.16-19-pve #1 SMP PREEMPT_DYNAMIC PMX 6.2.16-19 (2023-10-24T12:07Z) x86_64 x86_64 x86_64 GNU/Linux Subsystem esm hooks What steps will reproduce the bug? Setup...
X Description: Version 20.10 Platform Linux akala 6.2.16-19-pve #1 SMP PREEMPT_DYNAMIC PMX 6.2.16-19 (2023-10-24T12:07Z) x86_64 x86_64 x86_64 GNU/Linux Subsystem esm hooks What steps will reproduce the bug? Setup...
Opengraph URL: https://github.com/nodejs/node/issues/51128
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"custom Import attributes with esm hooks","articleBody":"### Version\r\n\r\n20.10\r\n\r\n### Platform\r\n\r\nLinux akala 6.2.16-19-pve #1 SMP PREEMPT_DYNAMIC PMX 6.2.16-19 (2023-10-24T12:07Z) x86_64 x86_64 x86_64 GNU/Linux\r\n\r\n### Subsystem\r\n\r\nesm hooks\r\n\r\n### What steps will reproduce the bug?\r\n\r\nSetup an ESM hook that handles a specific import attribute that relies on the builtin esm loader\r\n```js\r\nimport fs from 'fs/promise';\r\nimport { fileURLToPath } from 'url';\r\nexport async function load(url, context, nextLoad){\r\n \r\nif(context.importAttributes.type!=='x')\r\nreturn nextLoad(url, context)\r\n\r\n const source = await fs.readFile(fileURLToPath, 'utf8')\r\n\r\n return ({\r\n format: 'module',\r\n shortCircuit: true,\r\n source: source.replace(/import .*['\"][^'\"]+['\"]$/g, m=>m+'with {type:'x'}')\r\n })\r\n}\r\n```\r\n\r\n### How often does it reproduce? Is there a required condition?\r\n\r\nAlways\r\n\r\n### What is the expected behavior? Why is that the expected behavior?\r\n\r\nEither have a customAttribute hook to handle this validation or disable the validation when a custom hook is registered\r\n\r\n### What do you see instead?\r\n\r\nTypeError [ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED]: Import attribute type \"x\" is unsupported\r\n at handleInvalidType (node:internal/modules/esm/assert:106:11)\r\n at validateAttributes (node:internal/modules/esm/assert:78:14)\r\n at defaultLoad (node:internal/modules/esm/load:150:3)\r\n at async nextLoad (node:internal/modules/esm/hooks:865:22)\r\n at async nextLoad (node:internal/modules/esm/hooks:865:22)\r\n at async nextLoad (node:internal/modules/esm/hooks:865:22)\r\n at async Hooks.load (node:internal/modules/esm/hooks:448:20)\r\n at async handleMessage (node:internal/modules/esm/worker:196:18) {\r\n code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED'\r\n}\r\n\r\n### Additional information\r\n\r\n_No response_","author":{"url":"https://github.com/npenin","@type":"Person","name":"npenin"},"datePublished":"2023-12-12T06:18:21Z","url":"https://github.com/nodejs/node/issues/51128"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:895e37eb-0725-fd90-700a-2bbe1ac17e2f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B5E6:3865E3:6FF2CC:91A9E0:6AED2FB0 |
| html-safe-nonce | 5aa5e7d028683b19f9e46b841293cf84a7ff191b9a277a8139a46bf5e7aa17f9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNUU2OjM4NjVFMzo2RkYyQ0M6OTFBOUUwOjZBRUQyRkIwIiwidmlzaXRvcl9pZCI6IjE2NTM3MDIxOTkwNTQ1MTIwNDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3eeba7bc2964fbefec1b4dc023c3662eb9e7871aff8def6916c9620543a9a5cc |
| hovercard-subject-tag | issue:2037062385 |
| 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/51128/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b7783b92236684c7564dbcf2aa8cf6c3c155b359cc092adb3f305c09225c6515/nodejs/node/issues/51128 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b7783b92236684c7564dbcf2aa8cf6c3c155b359cc092adb3f305c09225c6515/nodejs/node/issues/51128 |
| og:image:alt | Version 20.10 Platform Linux akala 6.2.16-19-pve #1 SMP PREEMPT_DYNAMIC PMX 6.2.16-19 (2023-10-24T12:07Z) x86_64 x86_64 x86_64 GNU/Linux Subsystem esm hooks What steps will reproduce the bug? Setup... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | npenin |
| hostname | github.com |
| expected-hostname | github.com |
| None | e51d0b7b5ab34b1688c05b54c3ed17b8658b2fa9bca973a9c740683ccb12cf4a |
| 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 | 59ebb7b901cc154ecc179a44f266fcf69f343b30 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width