Skip to content

Commit

Permalink
fix(lib): Fix .next not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
yuaanlin committed Sep 19, 2023
1 parent 243eb46 commit e7561fa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/nodejs/nextjs/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func constructNextFunction(zeaburOutputDir, firstFuncPage, tmpDir string) error
return fmt.Errorf("create function dir: %w", err)
}

launcher, err := renderLauncher()
launcher, err := renderLauncher(tmpDir)
if err != nil {
return fmt.Errorf("render launcher: %w", err)
}
Expand All @@ -30,7 +30,7 @@ func constructNextFunction(zeaburOutputDir, firstFuncPage, tmpDir string) error
return fmt.Errorf("write launcher: %w", err)
}

err = cp.Copy(".next", path.Join(p, ".next"))
err = cp.Copy(path.Join(tmpDir, ".next"), path.Join(p, ".next"))
if err != nil {
return fmt.Errorf("copy .next: %w", err)
}
Expand Down
9 changes: 5 additions & 4 deletions internal/nodejs/nextjs/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
"path"
"strings"
"text/template"
)
Expand All @@ -13,8 +14,8 @@ import (
var launcherTemplate string

// getNextConfig read .next/required-server-files.json and return the config string that will be injected into launcher
func getNextConfig() (string, error) {
rsf, err := os.ReadFile(".next/required-server-files.json")
func getNextConfig(tmpDir string) (string, error) {
rsf, err := os.ReadFile(path.Join(tmpDir, ".next/required-server-files.json"))
if err != nil {
return "", fmt.Errorf("read required-server-files.json: %w", err)
}
Expand Down Expand Up @@ -43,8 +44,8 @@ func getNextConfig() (string, error) {
}

// renderLauncher will render the launcher.js template which used as the entrypoint of the serverless function
func renderLauncher() (string, error) {
nextConfig, err := getNextConfig()
func renderLauncher(tmpDir string) (string, error) {
nextConfig, err := getNextConfig(tmpDir)
if err != nil {
return "", fmt.Errorf("get next config: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/nodejs/nextjs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TransformServerless(image, workdir string) error {
return fmt.Errorf("copy public dir: %w", err)
}

nextConfig, err := getNextConfig()
nextConfig, err := getNextConfig(tmpDir)
if err != nil {
return fmt.Errorf("get next config: %w", err)
}
Expand Down

0 comments on commit e7561fa

Please sign in to comment.