Unverified Commit 82bad10a authored by Jonathan Wilsson's avatar Jonathan Wilsson Committed by GitHub

Fix babel-loader failing on JSON5 syntax (#26194)



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes

Fixes: https://github.com/vercel/next.js/issues/26163
parent 56292234
import { readFileSync } from 'fs'
import JSON5 from 'next/dist/compiled/json5'
import { createConfigItem, loadOptions } from 'next/dist/compiled/babel/core'
import loadConfig from 'next/dist/compiled/babel/core-lib-config'
......@@ -151,7 +152,7 @@ const isJsFile = /\.js$/
function getCustomBabelConfig(configFilePath: string) {
if (isJsonFile.exec(configFilePath)) {
const babelConfigRaw = readFileSync(configFilePath, 'utf8')
return JSON.parse(babelConfigRaw)
return JSON5.parse(babelConfigRaw)
} else if (isJsFile.exec(configFilePath)) {
return require(configFilePath)
}
......
{
"presets": [
[
"next/babel",
{
"preset-env": {
"modules": "commonjs" // Here's a comment
}
}
]
]
}
......@@ -17,4 +17,8 @@ describe('Babel', () => {
it('should allow setting targets to a string', async () => {
await nextBuild(join(__dirname, '../fixtures/targets-string'))
})
it('should allow babelrc JSON5 syntax', async () => {
await nextBuild(join(__dirname, '../fixtures/babel-json5'))
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment