Skip to content

Commit

Permalink
Fix for ENOENT yarn install error.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagob committed Sep 22, 2020
1 parent 9314214 commit 3eb59e4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
20 changes: 1 addition & 19 deletions packages/create-full-stack/src/copyTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,25 +379,7 @@ export default async function copyTemplate(options: {
if (packageTemplatePath) {
templatePath = path.dirname(packageTemplatePath);
} else {
try {
runYarn(projectPath, ["add", fullTemplate]);
} catch (error) {
console.error(
`An error occurred running \`yarn add ${fullTemplate}\`:`,
error.code,
error
);
if (error.code === "ENOENT") {
// Re-run yarn install if it throws an "ENOENT" error
// It's likely https://github.com/tiagob/create-full-stack/issues/123
// Unfortunately, this is a long existing issue with yarn
// https://github.com/yarnpkg/yarn/issues/4563
// https://github.com/yarnpkg/yarn/issues/2629
runYarn(projectPath, ["add", fullTemplate]);
} else {
throw error;
}
}
runYarn(projectPath, ["add", fullTemplate]);
templatePath = path.dirname(
require.resolve(path.join(fullTemplate, "package.json"), {
paths: [projectPath],
Expand Down
2 changes: 1 addition & 1 deletion packages/create-full-stack/src/createReactAppUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function isSafeToCreateProjectIn(root: string, name: string) {

export function shouldUseYarn() {
try {
execSync("yarnpkg --version", { stdio: "ignore" });
execSync("yarn --version", { stdio: "ignore" });
return true;
} catch (error) {
return false;
Expand Down
14 changes: 12 additions & 2 deletions packages/create-full-stack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ try {
}

async function run() {
// Inquirer prompt can run into the create-full-stack installation.
console.log();

const projectPath = path.resolve(projectName);
const appName = path.basename(projectPath);
checkAppName(appName);
Expand Down Expand Up @@ -195,10 +198,17 @@ async function run() {
hasGithubActions,
});

console.log(`Installing packages using yarnpkg...`);
console.log(`Installing packages using yarn...`);
console.log();
// This also, uninstalls the template
runYarn(projectName);
try {
runYarn(projectName);
} catch (error) {
console.warn(
"First install attempt failed. Likely https://github.com/yarnpkg/yarn/issues/2629. Trying again."
);
runYarn(projectName);
}

console.log("Building common...");
console.log();
Expand Down
5 changes: 2 additions & 3 deletions packages/create-full-stack/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import spawn from "cross-spawn";

export function runYarn(cwd: string, args: string[] = []) {
const command = "yarnpkg";
const command = "yarn";
const argsWithCwd = ["--cwd", cwd, ...args];
const proc = spawn.sync(command, argsWithCwd, { stdio: "inherit" });
if (proc.status !== 0) {
console.error(`\`${command} ${argsWithCwd.join(" ")}\` failed`);
process.exit(1);
throw new Error(`\`${command} ${argsWithCwd.join(" ")}\` failed`);
}
}

Expand Down

0 comments on commit 3eb59e4

Please sign in to comment.