diff --git a/packages/babel-core/src/config/files/configuration.ts b/packages/babel-core/src/config/files/configuration.ts index e900369a894a..713e0c355ab2 100644 --- a/packages/babel-core/src/config/files/configuration.ts +++ b/packages/babel-core/src/config/files/configuration.ts @@ -272,6 +272,8 @@ const readConfigJSON5 = makeStaticFileCache((filepath, content): ConfigFile => { throw new Error(`${filepath}: Expected config object but found array`); } + delete options["$schema"]; + return { filepath, dirname: path.dirname(filepath), diff --git a/packages/babel-core/test/config-chain.js b/packages/babel-core/test/config-chain.js index 01961fa7e110..b72c9e5ff684 100644 --- a/packages/babel-core/test/config-chain.js +++ b/packages/babel-core/test/config-chain.js @@ -1343,5 +1343,19 @@ describe("buildConfigChain", function () { }); }).toThrow(/Preset \/\* your preset \*\/ requires a filename/); }); + + it("should not throw error on $schema property in json config files", () => { + const filename = fixture( + "config-files", + "babel-config-json-$schema-property", + "babel.config.json", + ); + expect(() => { + babel.loadPartialConfig({ + filename, + cwd: path.dirname(filename), + }); + }).not.toThrow(); + }); }); }); diff --git a/packages/babel-core/test/fixtures/config/config-files/babel-config-json-$schema-property/babel.config.json b/packages/babel-core/test/fixtures/config/config-files/babel-config-json-$schema-property/babel.config.json new file mode 100644 index 000000000000..c5816342771e --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/babel-config-json-$schema-property/babel.config.json @@ -0,0 +1,3 @@ +{ + "$schema": "https://json.schemastore.org/babelrc" +} \ No newline at end of file