Help with build args #37
-
Hi! I am running into an error where the docker build can't find the package-lock.json file. Im wondering if I have the build context url wrong or if I am passing in the wrong relative path. Can someone help me understand what the buildContext and relativePathToWorkspace path are referring to so I can ensure to set these appropriately? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Wow, rookie mistake. Found that I was up too many directories! |
Beta Was this translation helpful? Give feedback.
-
The This is the base directory Docker uses to build your application. In the case of ExamplesMonorepo Example
deploy-app.ts: // ESM example
import { Stack, StackProps } from 'aws-cdk-lib'
import { Construct } from 'constructs'
import { NextjsGlobalFunctions } from 'cdk-nextjs'
import { fileURLToPath } from 'url'
export class DeployAppStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props)
new NextjsGlobalFunctions(this, 'NextApp', {
buildContext: fileURLToPath(new URL('../app', import.meta.url)),
healthCheckPath: '/api/health',
})
}
} In this case:
Non-Monorepo Example
deploy-app.ts: // ESM example
import { Stack, StackProps } from 'aws-cdk-lib'
import { Construct } from 'constructs'
import { NextjsGlobalFunctions } from 'cdk-nextjs'
import { fileURLToPath } from 'url'
export class DeployAppStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props)
new NextjsGlobalFunctions(this, 'NextApp', {
buildContext: fileURLToPath(new URL('../app', import.meta.url)),
healthCheckPath: '/api/health',
})
}
} In this case:
These examples are loosely based on what I am doing. That said, obviously with a different directory structure, a different relative path may be necessary. |
Beta Was this translation helpful? Give feedback.
The
buildContext
should point to the root directory of your Next.js app (wherepackage.json
andpackage-lock.json
are located).This is the base directory Docker uses to build your application. In the case of
NextjsGlobalFunctions
, thebuildContext
ensures Docker can locate the app's source files for packaging and deployment.Examples
Monorepo Example
deploy-app.ts: