Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-geckos-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: improve error message when the entrypoint is incorrect
9 changes: 2 additions & 7 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7122,9 +7122,7 @@ addEventListener('fetch', event => {});`

await expect(runWrangler("deploy")).rejects
.toThrowErrorMatchingInlineSnapshot(`
[Error: The expected output file at "." was not found after running custom build: node -e "4+4;".
The \`main\` property in your wrangler.toml file should point to the file generated by the custom build.
The provided entry-point path, ".", points to a directory, rather than a file.
[Error: The provided entry-point path, ".", points to a directory, rather than a file.

Did you mean to set the main field to one of:
\`\`\`
Expand All @@ -7137,11 +7135,8 @@ addEventListener('fetch', event => {});`
"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] The expected output file at \\".\\" was not found after running custom build: node -e \\"4+4;\\".
"X [ERROR] The provided entry-point path, \\".\\", points to a directory, rather than a file.

The \`main\` property in your wrangler.toml file should point to the file generated by the custom
build.
The provided entry-point path, \\".\\", points to a directory, rather than a file.

Did you mean to set the main field to one of:
\`\`\`
Expand Down
7 changes: 6 additions & 1 deletion packages/wrangler/src/__tests__/startup-profiling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ describe("wrangler check startup", () => {
await expect(
runWrangler("check startup --args 'abc'")
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: The entry-point file at "abc" was not found.]`
`
[Error: The entry-point file at "abc" was not found.

This might mean that your entry-point file needs to be generated (which is the general case when a framework is being used).
If that's the case please run your project's build command and try again.]
`
);
});

Expand Down
43 changes: 29 additions & 14 deletions packages/wrangler/src/deployment-bundle/run-custom-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from "node:path";
import { Writable } from "node:stream";
import chalk from "chalk";
import { execaCommand } from "execa";
import dedent from "ts-dedent";
import { configFileName } from "../config";
import { UserError } from "../errors";
import { logger } from "../logger";
Expand Down Expand Up @@ -63,15 +64,11 @@ export async function runCustomBuild(
assertEntryPointExists(
expectedEntryAbsolute,
expectedEntryRelative,
`The expected output file at "${expectedEntryRelative}" was not found after running custom build: ${build.command}.\n` +
`The \`main\` property in your ${configFileName(configPath)} file should point to the file generated by the custom build.`
build.command,
configPath
);
} else {
assertEntryPointExists(
expectedEntryAbsolute,
expectedEntryRelative,
`The entry-point file at "${expectedEntryRelative}" was not found.`
);
assertEntryPointExists(expectedEntryAbsolute, expectedEntryRelative);
}
}

Expand All @@ -81,14 +78,16 @@ export async function runCustomBuild(
function assertEntryPointExists(
expectedEntryAbsolute: string,
expectedEntryRelative: string,
errorMessage: string
customBuildCommand?: string,
configPath?: string
) {
if (!fileExists(expectedEntryAbsolute)) {
throw new UserError(
getMissingEntryPointMessage(
errorMessage,
expectedEntryAbsolute,
expectedEntryRelative
expectedEntryRelative,
customBuildCommand,
configPath
)
);
}
Expand All @@ -101,16 +100,17 @@ function assertEntryPointExists(
* nearby to the expected file path.
*/
function getMissingEntryPointMessage(
message: string,
absoluteEntryPointPath: string,
relativeEntryPointPath: string
relativeEntryPointPath: string,
customBuildCommand?: string,
configPath?: string
): string {
if (
existsSync(absoluteEntryPointPath) &&
statSync(absoluteEntryPointPath).isDirectory()
) {
// The expected entry-point is a directory, so offer further guidance.
message += `\nThe provided entry-point path, "${relativeEntryPointPath}", points to a directory, rather than a file.\n`;
let message = `The provided entry-point path, "${relativeEntryPointPath}", points to a directory, rather than a file.\n`;

// Perhaps we can even guess what the correct path should be...
const possiblePaths: string[] = [];
Expand All @@ -137,8 +137,23 @@ function getMissingEntryPointMessage(
possiblePaths.map((filePath) => `main = "./${filePath}"\n`).join("") +
"```";
}

return message;
}
return message;

if (customBuildCommand) {
return dedent`
The expected output file at "${relativeEntryPointPath}" was not found after running custom build: ${customBuildCommand}.
The \`main\` property in your ${configFileName(configPath)} file should point to the file generated by the custom build.
`;
}

return dedent`
The entry-point file at "${relativeEntryPointPath}" was not found.

This might mean that your entry-point file needs to be generated (which is the general case when a framework is being used).
If that's the case please run your project's build command and try again.
`;
}

/**
Expand Down
Loading