GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add `uncheckedRequire` option for JSON imports to CJS by nicolo-ribaudo · Pull Request #16579 · babel/babel

Conversation

@nicolo-ribaudo

@nicolo-ribaudo nicolo-ribaudo commented Jun 20, 2024

Copy link
Copy Markdown
Member
Q                       A
Fixed Issues? Fixes #16534
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

As #16534 shows, sometimes it is impossible to properly compile with { type: "json" } (specifically, when targeting CJS + browsers).

This PR makes that case an error, providing a workaround to compile import "x.json" with { type: "json" } to simply require("x.json"). Technically this is unsound, because there could be a x.json.js file what gets executed without asserting that it's actually JSON, but if you are using CJS you are not loading files from the network anyway.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BinToss reacted with heart emoji
All reactions
  • ❤️ 1 reaction
nicolo-ribaudo added 2 commits June 20, 2024 13:17
@nicolo-ribaudo
Throw error when compiling JSON imports to commonjs in the browser
b431405
@nicolo-ribaudo
Add uncheckedRequire option to transform JSON imports to require()
d20c275
@nicolo-ribaudo nicolo-ribaudo added PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: Import Attributes labels Jun 20, 2024
@nicolo-ribaudo nicolo-ribaudo added this to the v7.25.0 milestone Jun 20, 2024
@babel-bot

babel-bot commented Jun 20, 2024

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57184

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nicolo-ribaudo

nicolo-ribaudo commented Jun 20, 2024

Copy link
Copy Markdown
Member Author

We'll need to enable this flag in our config to fix #16491.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JLHwung
JLHwung approved these changes Jun 26, 2024
View reviewed changes
@JLHwung JLHwung added the PR: Needs Docs label Jun 26, 2024
liuxingbaoyu
liuxingbaoyu approved these changes Jun 28, 2024
View reviewed changes
@nicolo-ribaudo nicolo-ribaudo added the PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release label Jun 28, 2024
@nicolo-ribaudo nicolo-ribaudo removed the PR: Needs Docs label Jul 25, 2024
@nicolo-ribaudo nicolo-ribaudo mentioned this pull request Jul 25, 2024
Add docs for uncheckedRequire option babel/website#2928
Merged
@nicolo-ribaudo nicolo-ribaudo changed the title Add uncheckedRequire option to transform JSON imports to require() Add uncheckedRequire option for JSON imports to CJS Jul 26, 2024
@nicolo-ribaudo
nicolo-ribaudo merged commit 475d9db into babel:main Jul 26, 2024
@nicolo-ribaudo
nicolo-ribaudo deleted the json-modules-browser-commonjs branch July 26, 2024 09:24
This was referenced Aug 16, 2024
[Snyk] Upgrade: , nejidevelops/phase-0-javascript-events-acting-on-events-lab#50
Open
[Snyk] Upgrade: , nejidevelops/phase-0-intro-to-js-2-looping-code-along#50
Open
@ashly1111111 ashly1111111 mentioned this pull request Aug 16, 2024
[Snyk] Upgrade: , , , , ashly1111111/node#119
Open
@nejidevelops nejidevelops mentioned this pull request Aug 16, 2024
[Snyk] Upgrade: , nejidevelops/phase-0-intro-to-js-2-objects-lab#52
Open
@DevangPatelUK DevangPatelUK mentioned this pull request Aug 16, 2024
[Snyk] Upgrade @babel/runtime from 7.19.0 to 7.25.0 DevangPatelUK/BotFramework-WebChat#144
Open
@nejidevelops nejidevelops mentioned this pull request Aug 16, 2024
[Snyk] Upgrade: , nejidevelops/phase-1-destructuring-assignment#52
Open
@YinghanFeng YinghanFeng mentioned this pull request Aug 16, 2024
[Snyk] Upgrade @babel/runtime from 7.13.17 to 7.25.0 YinghanFeng/redux-orm#3
Open
This was referenced Aug 16, 2024
[Snyk] Upgrade @babel/runtime from 7.19.0 to 7.25.0 DevangPatelUK/BotFramework-WebChat#145
Open
[Snyk] Upgrade @babel/runtime from 7.17.2 to 7.25.0 DevangPatelUK/BotFramework-WebChat#146
Open
@jamesleesaunders jamesleesaunders mentioned this pull request Aug 16, 2024
[Snyk] Upgrade: , jamesleesaunders/d3-ez#202
Merged
@snyk-io snyk-io Bot mentioned this pull request Aug 17, 2024
[Snyk] Upgrade @babel/runtime from 7.4.3 to 7.25.0 Playgirlkaybraz11/td#13
Open
This was referenced Aug 17, 2024
[Snyk] Upgrade: , tiff-es/fewpjs-adding-behavior-with-methods-dc-web-091619#220
Open
[Snyk] Upgrade: , tiff-es/fewpjs-class-extensions-super-lab-online-web-sp-000#207
Open
[Snyk] Upgrade: , tiff-es/fewpjs-acting-on-events-dc-web-091619#205
Open
This was referenced Oct 29, 2024
[Snyk] Upgrade @babel/parser from 7.1.3 to 7.25.7 Mhmonicox/node#162
Open
[Snyk] Upgrade @babel/traverse from 7.1.4 to 7.25.7 Mhmonicox/node#163
Open
[Snyk] Upgrade @babel/generator from 7.1.3 to 7.25.7 Mhmonicox/node#164
Open
[Snyk] Upgrade @babel/types from 7.1.3 to 7.25.7 Mhmonicox/node#165
Open
[Snyk] Upgrade @babel/template from 7.1.2 to 7.25.7 Mhmonicox/node#166
Open
@nejidevelops nejidevelops mentioned this pull request Oct 29, 2024
[Snyk] Upgrade @babel/preset-env from 7.18.2 to 7.25.7 nejidevelops/phase-0-intro-to-js-2-objects-lab#104
Open
@ali8889 ali8889 mentioned this pull request Oct 30, 2024
[Snyk] Upgrade @babel/runtime from 7.0.0-beta.42 to 7.25.7 ali8889/mist#666
Open
This was referenced Oct 30, 2024
[Snyk] Upgrade @babel/preset-env from 7.18.10 to 7.25.7 rawdaymohamed/Hot-Todo#411
Closed
[Snyk] Upgrade @babel/node from 7.18.10 to 7.25.7 rawdaymohamed/Hot-Todo#413
Closed
@tiff-es tiff-es mentioned this pull request Oct 30, 2024
[Snyk] Upgrade @babel/preset-env from 7.4.5 to 7.25.7 tiff-es/fewpjs-adding-behavior-with-methods-dc-web-091619#254
Open
@syofyanzuhad syofyanzuhad mentioned this pull request Oct 30, 2024
[Snyk] Upgrade @babel/runtime from 7.23.4 to 7.25.7 syofyanzuhad/profile#149
Open
@anandgupta193 anandgupta193 mentioned this pull request Oct 30, 2024
[Snyk] Upgrade @babel/node from 7.10.4 to 7.25.7 anandgupta193/sortNsuffle-react#1145
Open
@mastudillot mastudillot mentioned this pull request Oct 30, 2024
[Snyk] Upgrade @babel/runtime from 7.14.0 to 7.25.7 TransbankDevelopers/transbank-pos-sdk-nodejs#38
Merged
@lholmquist lholmquist mentioned this pull request Oct 30, 2024
[Snyk] Upgrade @babel/preset-env from 7.22.9 to 7.25.7 nodeshift/opossum#900
Closed
@DevangPatelUK DevangPatelUK mentioned this pull request Oct 30, 2024
[Snyk] Upgrade @babel/runtime from 7.17.2 to 7.25.7 DevangPatelUK/BotFramework-WebChat#473
Open
@junInUK junInUK mentioned this pull request Oct 31, 2024
[Snyk] Upgrade @babel/runtime from 7.17.9 to 7.25.7 junInUK/meteor-blaze-reminders#78
Open
@bee22193 bee22193 mentioned this pull request Oct 31, 2024
[Snyk] Upgrade @babel/preset-env from 7.8.2 to 7.25.7 bee22193/mnmlurl#1272
Open
@richyhoopd richyhoopd mentioned this pull request Oct 31, 2024
[Snyk] Upgrade @babel/preset-env from 7.4.5 to 7.25.7 richyhoopd/RichyFlix#939
Open
This was referenced Oct 31, 2024
[Snyk] Upgrade @babel/parser from 7.1.3 to 7.25.8 ashly1111111/node#147
Open
[Snyk] Upgrade @babel/traverse from 7.1.4 to 7.25.7 ashly1111111/node#148
Open
[Snyk] Upgrade @babel/generator from 7.1.3 to 7.25.7 ashly1111111/node#149
Open
[Snyk] Upgrade @babel/types from 7.1.3 to 7.25.8 ashly1111111/node#150
Open
[Snyk] Upgrade @babel/template from 7.1.2 to 7.25.7 ashly1111111/node#151
Open
@NOUIY NOUIY mentioned this pull request Oct 31, 2024
[Snyk] Upgrade @babel/runtime from 7.17.9 to 7.25.7 NOUIY/videojs-ogvjs#36
Open
@basharat-j basharat-j mentioned this pull request Nov 1, 2024
[Snyk] Upgrade @babel/runtime from 7.13.10 to 7.25.7 basharat-j/mb-graphql#74
Open
@YoYBaBy YoYBaBy mentioned this pull request Nov 1, 2024
[Snyk] Upgrade @babel/preset-env from 7.8.4 to 7.25.8 YoYBaBy/docs#875
Open
@nejidevelops nejidevelops mentioned this pull request Nov 2, 2024
[Snyk] Upgrade @babel/preset-env from 7.4.5 to 7.25.8 nejidevelops/phase-1-destructuring-assignment#104
Open
@richyhoopd richyhoopd mentioned this pull request Nov 2, 2024
[Snyk] Upgrade @babel/preset-env from 7.9.0 to 7.25.8 richyhoopd/Video-App#1242
Open
@github-actions github-actions Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Nov 2, 2024
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@JLHwung JLHwung JLHwung approved these changes
@liuxingbaoyu liuxingbaoyu liuxingbaoyu approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release Spec: Import Attributes

Projects

None yet

Milestone

v7.25.0

Development

Successfully merging this pull request may close these issues.

[Bug]: @babel/plugin-proposal-json-module may output some ESM code (or even call undefined as if it's a function) to CJS outputs

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@nicolo-ribaudo @babel-bot @JLHwung @liuxingbaoyu
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.