Open ghsyeung opened 3 years ago
If basePath is set in next.config.js, the build would put static assets within ${sererlessBuildOutDir}/assets/${basePath}.
basePath
next.config.js
${sererlessBuildOutDir}/assets/${basePath}
However, in the CDK construct (NextJSLambdaEdge), it tries to read the assets from ${sererlessBuildOutDir}/assets without including the basePath
NextJSLambdaEdge
${sererlessBuildOutDir}/assets
https://github.com/serverless-nextjs/serverless-next.js/blob/145c16d9e163aca7b5f6a753f60404363c842b8f/packages/serverless-components/nextjs-cdk-construct/src/index.ts#L404
The function returns with an empty assets object leading to none of the assets being uploaded.
assets
Similar code in s3-static-assets handle this correctly
https://github.com/serverless-nextjs/serverless-next.js/blob/145c16d9e163aca7b5f6a753f60404363c842b8f/packages/libs/s3-static-assets/src/index.ts#L67
The fix looks relatively straight forward and it works for my use case.
const { basePath } = this.routesManifest || {}; const normalizedBasePath = basePath && basePath.length > 0? basePath.slice(1) : ""; const assets = readAssetsDirectory({ assetsDirectory: path.join(assetsDirectory, normalizedBasePath) });
Thanks @ghsyeung. Feel free to raise a PR to fix it and I'll merge it.
If
basePath
is set innext.config.js
, the build would put static assets within${sererlessBuildOutDir}/assets/${basePath}
.However, in the CDK construct (
NextJSLambdaEdge
), it tries to read the assets from${sererlessBuildOutDir}/assets
without including thebasePath
https://github.com/serverless-nextjs/serverless-next.js/blob/145c16d9e163aca7b5f6a753f60404363c842b8f/packages/serverless-components/nextjs-cdk-construct/src/index.ts#L404
The function returns with an empty
assets
object leading to none of the assets being uploaded.Similar code in s3-static-assets handle this correctly
https://github.com/serverless-nextjs/serverless-next.js/blob/145c16d9e163aca7b5f6a753f60404363c842b8f/packages/libs/s3-static-assets/src/index.ts#L67
The fix looks relatively straight forward and it works for my use case.