Add check for invalid assetPrefix (#9759)
* Add check for invalid assetPrefix * Update test/integration/invalid-config-values/test/index.test.js Co-Authored-By: JJ Kasper <jj@jjsweb.site>
This commit is contained in:
parent
a32af59e93
commit
2ba056aa20
4 changed files with 87 additions and 0 deletions
17
errors/invalid-assetprefix.md
Normal file
17
errors/invalid-assetprefix.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Invalid assetPrefix
|
||||
|
||||
#### Why This Error Occurred
|
||||
|
||||
The value of `assetPrefix` in `next.config.js` is set to something that is not a `string`.
|
||||
|
||||
#### Possible Ways to Fix It
|
||||
|
||||
Ensure that `assetPrefix` is a `string`.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
assetPrefix: '/',
|
||||
}
|
||||
```
|
|
@ -100,6 +100,12 @@ function assignDefaults(userConfig: { [key: string]: any }) {
|
|||
})
|
||||
|
||||
const result = { ...defaultConfig, ...userConfig }
|
||||
|
||||
if (typeof result.assetPrefix !== 'string') {
|
||||
throw new Error(
|
||||
`Specified assetPrefix is not a string, found type "${typeof result.assetPrefix}" https://err.sh/zeit/next.js/invalid-assetprefix`
|
||||
)
|
||||
}
|
||||
if (result.experimental && result.experimental.css) {
|
||||
// The new CSS support requires granular chunks be enabled.
|
||||
result.experimental.granularChunks = true
|
||||
|
|
1
test/integration/invalid-config-values/pages/index.js
Normal file
1
test/integration/invalid-config-values/pages/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export default () => 'hi'
|
63
test/integration/invalid-config-values/test/index.test.js
Normal file
63
test/integration/invalid-config-values/test/index.test.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
/* eslint-env jest */
|
||||
/* global jasmine */
|
||||
import fs from 'fs-extra'
|
||||
import { join } from 'path'
|
||||
import { nextBuild } from 'next-test-utils'
|
||||
|
||||
const appDir = join(__dirname, '../')
|
||||
const nextConfigPath = join(appDir, 'next.config.js')
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
|
||||
|
||||
const cleanUp = () => fs.remove(nextConfigPath)
|
||||
|
||||
describe('Handles valid/invalid assetPrefix', () => {
|
||||
beforeAll(() => cleanUp())
|
||||
afterAll(() => cleanUp())
|
||||
|
||||
it('should not error without usage of assetPrefix', async () => {
|
||||
await fs.writeFile(
|
||||
nextConfigPath,
|
||||
`module.exports = {
|
||||
}`
|
||||
)
|
||||
|
||||
const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
|
||||
expect(stderr).not.toMatch(/Specified assetPrefix is not a string/)
|
||||
})
|
||||
|
||||
it('should not error when assetPrefix is a string', async () => {
|
||||
await fs.writeFile(
|
||||
nextConfigPath,
|
||||
`module.exports = {
|
||||
assetPrefix: '/hello'
|
||||
}`
|
||||
)
|
||||
|
||||
const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
|
||||
expect(stderr).not.toMatch(/Specified assetPrefix is not a string/)
|
||||
})
|
||||
|
||||
it('should error on wrong usage of assetPrefix', async () => {
|
||||
await fs.writeFile(
|
||||
nextConfigPath,
|
||||
`module.exports = {
|
||||
assetPrefix: null
|
||||
}`
|
||||
)
|
||||
|
||||
const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
|
||||
expect(stderr).toMatch(/Specified assetPrefix is not a string/)
|
||||
})
|
||||
|
||||
it('should error on usage of assetPrefix with undefined as value', async () => {
|
||||
await fs.writeFile(
|
||||
nextConfigPath,
|
||||
`module.exports = {
|
||||
assetPrefix: undefined
|
||||
}`
|
||||
)
|
||||
|
||||
const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
|
||||
expect(stderr).toMatch(/Specified assetPrefix is not a string/)
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue