Skip to content

Commit

Permalink
Fix next/config module mismatch in new serverless mode (#10792)
Browse files Browse the repository at this point in the history
* Add failing test case

* Update serverless-loader require to fix config module mismatch

Co-authored-by: Joe Haddad <timer150@gmail.com>
  • Loading branch information
ijjk and Timer committed Mar 2, 2020
1 parent 2b74db7 commit 9ec3dae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Expand Up @@ -62,7 +62,7 @@ const nextServerlessLoader: loader.Loader = function() {

const runtimeConfigImports = runtimeConfig
? `
const { setConfig } = require('next/dist/next-server/lib/runtime-config')
const { setConfig } = require('next/config')
`
: ''

Expand Down
28 changes: 21 additions & 7 deletions test/integration/serverless-runtime-configs/test/index.test.js
Expand Up @@ -31,15 +31,16 @@ const nextStart = async (appDir, appPort) => {
)
}

describe('Serverless runtime configs', () => {
beforeAll(() => cleanUp())
afterAll(() => cleanUp())
const runTests = (oldServerless = false) => {
const serverlessMode = oldServerless
? 'serverless'
: 'experimental-serverless-trace'

it('should not error on usage of publicRuntimeConfig', async () => {
await fs.writeFile(
nextConfigPath,
`module.exports = {
target: 'serverless',
target: '${serverlessMode}',
publicRuntimeConfig: {
hello: 'world'
}
Expand All @@ -59,7 +60,7 @@ describe('Serverless runtime configs', () => {
await fs.writeFile(
nextConfigPath,
`module.exports = {
target: 'serverless',
target: '${serverlessMode}',
serverRuntimeConfig: {
hello: 'world'
}
Expand Down Expand Up @@ -130,7 +131,7 @@ describe('Serverless runtime configs', () => {
await fs.writeFile(
nextConfigPath,
`module.exports = {
target: 'serverless',
target: '${serverlessMode}',
serverRuntimeConfig: {
hello: 'world'
},
Expand All @@ -150,7 +151,7 @@ describe('Serverless runtime configs', () => {
await fs.writeFile(
nextConfigPath,
`module.exports = {
target: 'serverless',
target: '${serverlessMode}',
serverRuntimeConfig: {
hello: 'world'
},
Expand All @@ -164,4 +165,17 @@ describe('Serverless runtime configs', () => {
const app = await launchApp(appDir, appPort)
await testRuntimeConfig(app, appPort)
})
}

describe('Serverless runtime configs', () => {
beforeAll(() => cleanUp())
afterAll(() => cleanUp())

describe('legacy serverless mode', () => {
runTests(true)
})

describe('experimental-serverless-trace mode', () => {
runTests()
})
})

0 comments on commit 9ec3dae

Please sign in to comment.