René's URL Explorer Experiment


Title: Feature: ESM in .js files · Issue #151 · nodejs/modules · GitHub

Open Graph Title: Feature: ESM in .js files · Issue #151 · nodejs/modules

X Title: Feature: ESM in .js files · Issue #151 · nodejs/modules

Description: There needs to be a way to tell Node to treat .js files as ESM JavaScript. Besides the issue raised in #149, there’s the use case of legacy build tools and pipelines that expect only a single file extension for JavaScript. I can give a c...

Open Graph Description: There needs to be a way to tell Node to treat .js files as ESM JavaScript. Besides the issue raised in #149, there’s the use case of legacy build tools and pipelines that expect only a single file ...

X Description: There needs to be a way to tell Node to treat .js files as ESM JavaScript. Besides the issue raised in #149, there’s the use case of legacy build tools and pipelines that expect only a single file ...

Opengraph URL: https://github.com/nodejs/modules/issues/151

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature: ESM in .js files","articleBody":"There needs to be a way to tell Node to treat `.js` files as ESM JavaScript.\r\n\r\nBesides the issue raised in [#149](https://github.com/nodejs/modules/issues/149), there’s the use case of legacy build tools and pipelines that expect only a single file extension for JavaScript. I can give a concrete example for the case of CoffeeScript. The problem is that essentially, the CoffeeScript compiler is a string converter. It takes a string as input, like `console.log 'hello!'`, and returns another string as output: `console.log('hello!');` People who use the CoffeeScript compiler as their entire build chain (as opposed to using it within Gulp or Webpack or the like) use it to transpile projects like this:\r\n\r\n```bash\r\ncoffee --compile --output dist/ src/\r\n```\r\n\r\nThis command recursively searches `src/` for all `*.coffee`, `*.litcoffee` and `*.litcoffee.md` files, runs them through the CoffeeScript compiler, and saves them as `*.js` files in a mirrored folder tree under `dist/`.\r\n\r\nCoffeeScript doesn’t know the parse goals of the files in `src/`. It doesn’t know which ones to save with a `.js` extension versus an `.mjs` extension. About the only way it _could_ know is if we created new file extensions, like `.mcoffee`, `.mlitcoffee` and `.mlitcoffee.md`, that it knew to output as `.mjs`. But that’s not a practical solution, as there are thousands of CoffeeScript build plugins and syntax highlighters and so on out there that would need to be updated to support these new file extensions; and let’s be honest, most of those packages are abandoned. Adding a new option, like `--output-file-extension mjs`, also isn’t realistic for the same reason, because of the sheer number of build plugins that would need to be updated to support it. CoffeeScript traditionally just converts one string into another, without necessarily reading or passing along any other options or metadata, and there are lots of build pipelines that expect this behavior.\r\n\r\nRather than figuring out a way to add a piece of metadata (the parse goal) to CoffeeScript source files, and then updating all other parts of the build chain to preserve and pass along and understand this new metadata, it would be better if the parse goal could be specified outside of the file itself.\r\n\r\nThere’s already one implementation to achieve this: [nodejs/node#18392](https://github.com/nodejs/node/pull/18392), which suggests a `mode` flag for `package.json` files to tell Node to treat `.js` files as ES modules within a given package boundary. There’s also the suggestion [here](https://github.com/GeoffreyBooth/modules/blob/85f0bffde459f82e1603a149d60d2ca7bec4105d/proposals/esm-in-js-files.md#packagejson-section-to-tell-node-how-to-handle-any-file) expand that idea to create a whole new section in `package.json` where users can assign MIME types for file extensions, essentially telling Node how to parse any type of file. Either of these solutions would work.\r\n\r\nWe have the same issue for input that doesn’t come from files, such as from STDIN or via `--eval`. There needs to be some way to tell Node to treat those inputs as ESM, such as a CLI flag:\r\n\r\n```bash\r\nnode --module --eval 'import path from \"path\"; console.log(path.sep);'\r\n```\r\n\r\nThese suggestions are _complements_ for `.mjs`, not replacements. These proposals don’t provide easy ways to keep CommonJS and ESM files side-by-side in the same folder, for example. These are solutions for use cases that go unfulfilled by `.mjs`.\r\n\r\nOne final note: I don’t claim to speak for other compile-to-JavaScript languages, like TypeScript or JSX, but I wouldn’t be surprised if many of them had [similar issues](https://github.com/Microsoft/TypeScript/issues/18442). There are also other categories of build tools and plugins, like linters and minifiers, that may be affected. For maximum compatibility, we should provide multiple ways to signal ESM mode to Node.","author":{"url":"https://github.com/GeoffreyBooth","@type":"Person","name":"GeoffreyBooth"},"datePublished":"2018-07-12T02:04:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/151/modules/issues/151"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:923895cf-256f-72b4-20aa-ccfa7ad4c679
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8442:CD884:F1EAE3:150DA1F:6A4E8BA3
html-safe-nonce6b71f50858a387527ce435400ef3acc0253d520aa2dc65879d1ddfd305dcc1bf
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDQyOkNEODg0OkYxRUFFMzoxNTBEQTFGOjZBNEU4QkEzIiwidmlzaXRvcl9pZCI6IjI3NTgyNjk3MjQ4ODIwMTMwOTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac1d589db1d4ed9c6574fb8816a9198a3ce24279b71faa1dd06b1f9015b63ac3df
hovercard-subject-tagissue:340463837
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/modules/151/issue_layout
twitter:imagehttps://opengraph.githubassets.com/932504a4284b5fc292f7d4aefcea5ea2d48b350bf8093f1d3361d0060b238e51/nodejs/modules/issues/151
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/932504a4284b5fc292f7d4aefcea5ea2d48b350bf8093f1d3361d0060b238e51/nodejs/modules/issues/151
og:image:altThere needs to be a way to tell Node to treat .js files as ESM JavaScript. Besides the issue raised in #149, there’s the use case of legacy build tools and pipelines that expect only a single file ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameGeoffreyBooth
hostnamegithub.com
expected-hostnamegithub.com
None41b6ab3ba6d20a71766ac245b5a4a94c6fc672a9cd4da7d44c1b33ab8bf6a21c
turbo-cache-controlno-preview
go-importgithub.com/nodejs/modules git https://github.com/nodejs/modules.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id119901830
octolytics-dimension-repository_nwonodejs/modules
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id119901830
octolytics-dimension-repository_network_root_nwonodejs/modules
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
releasee6a744804e8e70f97b4d5a18a94dcc63db22f97a
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/nodejs/modules/issues/151#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fmodules%2Fissues%2F151
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fmodules%2Fissues%2F151
Sign up https://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%2Fmodules
Reloadhttps://github.com/nodejs/modules/issues/151
Reloadhttps://github.com/nodejs/modules/issues/151
Reloadhttps://github.com/nodejs/modules/issues/151
Please reload this pagehttps://github.com/nodejs/modules/issues/151
nodejs https://github.com/nodejs
moduleshttps://github.com/nodejs/modules
Notifications https://github.com/login?return_to=%2Fnodejs%2Fmodules
Fork 43 https://github.com/login?return_to=%2Fnodejs%2Fmodules
Star 411 https://github.com/login?return_to=%2Fnodejs%2Fmodules
Code https://github.com/nodejs/modules
Issues 26 https://github.com/nodejs/modules/issues
Pull requests 0 https://github.com/nodejs/modules/pulls
Actions https://github.com/nodejs/modules/actions
Projects https://github.com/nodejs/modules/projects
Security and quality 0 https://github.com/nodejs/modules/security
Insights https://github.com/nodejs/modules/pulse
Code https://github.com/nodejs/modules
Issues https://github.com/nodejs/modules/issues
Pull requests https://github.com/nodejs/modules/pulls
Actions https://github.com/nodejs/modules/actions
Projects https://github.com/nodejs/modules/projects
Security and quality https://github.com/nodejs/modules/security
Insights https://github.com/nodejs/modules/pulse
Feature: ESM in .js fileshttps://github.com/nodejs/modules/issues/151#top
esmhttps://github.com/nodejs/modules/issues?q=state%3Aopen%20label%3A%22esm%22
featureshttps://github.com/nodejs/modules/issues?q=state%3Aopen%20label%3A%22features%22
https://github.com/GeoffreyBooth
GeoffreyBoothhttps://github.com/GeoffreyBooth
on Jul 12, 2018https://github.com/nodejs/modules/issues/151#issue-340463837
#149https://github.com/nodejs/modules/issues/149
nodejs/node#18392https://github.com/nodejs/node/pull/18392
herehttps://github.com/GeoffreyBooth/modules/blob/85f0bffde459f82e1603a149d60d2ca7bec4105d/proposals/esm-in-js-files.md#packagejson-section-to-tell-node-how-to-handle-any-file
similar issueshttps://github.com/Microsoft/TypeScript/issues/18442
esmhttps://github.com/nodejs/modules/issues?q=state%3Aopen%20label%3A%22esm%22
featureshttps://github.com/nodejs/modules/issues?q=state%3Aopen%20label%3A%22features%22
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.