alephmatic / full-stack-ai

Generate a full-stack Next.js app from an AI prompt
https://fsai.elie.tech
259 stars 44 forks source link

Syntax error: "(" unexpected #3

Open Lanzelot-Moll opened 11 months ago

Lanzelot-Moll commented 11 months ago

I tried to run it locally in Ubuntu VM on Mac M1 Max

npx fsai gen "Build a clone of Twitter called StackPrompt where people prompt instead of tweet. Allow users to follow one another and to like prompts. Use GitHub for log in. Charge users a monthly fee for premium functionality."

GOT:

/home/parallels/.nvm/versions/node/v20.10.0/bin/fsai: 1: Syntax error: "(" unexpected

Lanzelot-Moll commented 11 months ago

locally:

npx tsx src/index.ts gen "Build a clone of Twitter called StackPrompt where people prompt instead of tweet. Allow users to follow one another and to like prompts. Use GitHub for log in. Charge users a monthly fee for premium functionality." Generating code with AI... 2:00:44 PM

message { role: 'system', 2:00:44 PM content: "You are an AI that builds full-stack apps for users.\nYou are able to call functions to build the app.\nBuild what you can with the functions.\nAfter you've done your work scafolding the app as much as you can, the user will take over and complete the work." } message { role: 'user', 2:00:44 PM content: 'Build a clone of Twitter called StackPrompt where people prompt instead of tweet. Allow users to follow one another and to like prompts. Use GitHub for log in. Charge users a monthly fee for premium functionality.' } message { role: 'assistant', 2:00:46 PM content: null, function_call: { name: 'createNextApp', arguments: '{"appName":"StackPrompt"}' } } Creating Next.js app stackprompt in /home/parallels/workspace/DemoShop/AITest/full-stack-ai 2:00:46 PM The directory stackprompt contains files that could conflict:

.eslintrc.json README.md app/ next-env.d.ts next.config.js package.json postcss.config.js public/ tailwind.config.ts tsconfig.json

Either try using a new directory name, or remove the files listed above.

[2:00:47 PM] ERROR Error creating Next.js app: Command failed with exit code 1: npx create-next-app@latest stackprompt --typescript --eslint --use-pnpm --tailwind --app --no-src-dir --import-alias @/*

at makeError (node_modules/execa/lib/error.js:60:11) at handlePromise (node_modules/execa/index.js:124:26) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at createNextApp (src/actions.ts:26:32) at Object.function (src/actions.ts:157:11) at ChatCompletionRunner._runFunctions (node_modules/openai/src/lib/AbstractChatCompletionRunner.ts:527:26)

ERROR Error createNextApp app. Args: { 2:00:47 PM "appName": "StackPrompt" } Error: Command failed with exit code 1: npx create-next-app@latest stackprompt --typescript --eslint --use-pnpm --tailwind --app --no-src-dir --import-alias @/*

at makeError (node_modules/execa/lib/error.js:60:11) at handlePromise (node_modules/execa/index.js:124:26) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at createNextApp (src/actions.ts:26:32) at Object.function (src/actions.ts:157:11) at ChatCompletionRunner._runFunctions (node_modules/openai/src/lib/AbstractChatCompletionRunner.ts:527:26)

/home/parallels/workspace/DemoShop/AITest/full-stack-ai/node_modules/openai/src/lib/AbstractChatCompletionRunner.ts:338 const openAIError: OpenAIError = new OpenAIError(error.message); ^

OpenAIError: Command failed with exit code 1: npx create-next-app@latest stackprompt --typescript --eslint --use-pnpm --tailwind --app --no-src-dir --import-alias @/ at (/home/parallels/workspace/DemoShop/AITest/full-stack-ai/node_modules/openai/src/lib/AbstractChatCompletionRunner.ts:338:40) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { cause: Error: Command failed with exit code 1: npx create-next-app@latest stackprompt --typescript --eslint --use-pnpm --tailwind --app --no-src-dir --import-alias @/ at makeError (file:///home/parallels/workspace/DemoShop/AITest/full-stack-ai/node_modules/execa/lib/error.js:60:11) at handlePromise (file:///home/parallels/workspace/DemoShop/AITest/full-stack-ai/node_modules/execa/index.js:124:26) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at createNextApp (/home/parallels/workspace/DemoShop/AITest/full-stack-ai/src/actions.ts:26:32) at Object.function (/home/parallels/workspace/DemoShop/AITest/full-stack-ai/src/actions.ts:157:11) at ChatCompletionRunner._runFunctions (/home/parallels/workspace/DemoShop/AITest/full-stack-ai/node_modules/openai/src/lib/AbstractChatCompletionRunner.ts:527:26) { shortMessage: 'Command failed with exit code 1: npx create-next-app@latest stackprompt --typescript --eslint --use-pnpm --tailwind --app --no-src-dir --import-alias @/', command: 'npx create-next-app@latest stackprompt --typescript --eslint --use-pnpm --tailwind --app --no-src-dir --import-alias @/', escapedCommand: 'npx "create-next-app@latest" stackprompt --typescript --eslint --use-pnpm --tailwind --app --no-src-dir --import-alias "@/*"', exitCode: 1, signal: undefined, signalDescription: undefined, stdout: undefined, stderr: undefined, cwd: '/home/parallels/workspace/DemoShop/AITest/full-stack-ai', failed: true, timedOut: false, isCanceled: false, killed: false } }

Node.js v20.10.0

elie222 commented 11 months ago

Hey, Next.js app creation fails for this reason:

"Either try using a new directory name, or remove the files listed above."

Delete the existing stackprompt folder, or try using a different name for the app.

This is unrelated to the first message: "Syntax error: "(" unexpected" Does fsai still not work for you? I updated it recently. Try using npx fsai@latest

chrisedington commented 11 months ago

Also getting this error on node 17.6.

Lanzelot-Moll commented 11 months ago

I ran this in a new VM on node 20 now. Syntax error with "(" is still the same. But locally throws:

npx tsx src/index.ts gen "Build a clone of Twitter called StackPrompt where people prompt instead of tweet. Allow users to follow one another and to like prompts. Use GitHub for log in. Charge users a monthly fee for premium functionality."

node:internal/process/esm_loader:40 internalBinding('errors').triggerUncaughtException( ^ Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/parallels/workspace/projects/test fsai/src/index.ts' imported from /home/parallels/workspace/projects/test fsai/ at finalizeResolution (node:internal/modules/esm/resolve:255:11) at moduleResolve (node:internal/modules/esm/resolve:908:10) at defaultResolve (node:internal/modules/esm/resolve:1121:11) at nextResolve (node:internal/modules/esm/hooks:865:28) at d (file:///home/parallels/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/esm/index.mjs:5:34) at O (file:///home/parallels/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/esm/index.mjs:5:1187) at nextResolve (node:internal/modules/esm/hooks:865:28) at Hooks.resolve (node:internal/modules/esm/hooks:303:30) at handleMessage (node:internal/modules/esm/worker:196:24) at Immediate.checkForMessages (node:internal/modules/esm/worker:138:28) { code: 'ERR_MODULE_NOT_FOUND', url: 'file:///home/parallels/workspace/projects/test%20fsai/src/index.ts' }

Node.js v20.10.0

projik commented 11 months ago

I get the same error message with the same prompt. I've tried with npx and installing fsai.

fsai gen "Build a clone of Twitter called StackPrompt where people prompt instead of tweet. Allow users to follow one another and to like prompts. Use GitHub for log in. Charge users a monthly fee for premium functionality."

/usr/local/bin/fsai: line 1: syntax error near unexpected token `('
/usr/local/bin/fsai: line 1: `import"dotenv/config";import{Command as J}from"commander";import"dotenv/config";import d from"consola";import C from"openai";import n from"consola";import{execa as g}from"execa";import{z as r}from"zod";import{zodToJsonSchema as l}from"zod-to-json-schema";var m=r.object({appName:r.string().describe("The name of the Next.js app.")}),y=l(m),u=r.object({authType:r.enum(["next-auth","clerk","lucia","kinde"]).describe('The authentication type to use. Default to "next-auth".'),authProviders:r.array(r.enum(["discord","google","github","apple"])).default([]).describe("The authentication providers to use. Use just one option unless the user requests for more."),miscPackages:r.array(r.enum(["stripe","resend"])).describe("The packages to use. Stripe is used for payments. Resend is used to send emails."),orm:r.enum(["prisma","drizzle"]).default("prisma").describe("The ORM to use. Default to 'prisma'."),db:r.enum(["pg","mysql","sqlite"]).default("pg").describe('The database to use. Default to "pg".'),packageManager:r.enum(["npm","yarn","pnpm","bun"]).default("pnpm").describe("The package manager to use. Default to 'pnpm'.")}),x=l(u),I=r.enum(["varchar","text","number","float","boolean","references","timestamp","date","string"]),f=r.object({table:r.string().describe("The name of the database table. Should be in snake_case and plural."),belongsToUser:r.boolean().optional().default(!1).describe("Whether the resource belongs to the user. If true, a userId field will be added to the model."),index:r.string().optional().describe("The name of an index to add to the database table. Should be in snake_case. Must be a field in the table."),fields:r.array(r.object({name:r.string().describe("The name of the field."),type:I.describe("The type of the field. Choose a type appropriate to the selected database."),references:r.string().default("").describe("The name of the table that the field references. Do not set a reference for `userId`. Use `belongsToUser` instead. If type of the field is not `Reference` this field is empty."),notNull:r.boolean().describe("Whether the field is not null. If true, the field will be required."),cascade:r.boolean().describe("Whether the field cascades. If true, the field will cascade.")}).transform(t=>{let e=t.references==="user"||t.references==="users"||t.references==="userId"?void 0:t.references,a=t.type==="references"&&!e?"string":t.type;return{...t,type:a,references:e}})).describe("The fields of the database table. Do not include user. `belongsToUser` handles this.").transform(t=>t.filter(e=>e.name!=="user"&&e.name!=="users"&&e.name!=="userId"))}).transform(t=>{let e=t.fields.find(a=>a.name===t.index);return{...t,index:e?t.index:void 0}}),w=l(f),N={varchar:"String",text:"String",number:"Int",float:"Float",boolean:"Boolean",references:"References",timestamp:"DateTime",date:"DateTime",string:"String"};var c,h;async function z(t){c=t.appName.toLowerCase().replace(" ","-"),n.log("Creating Next.js app",c,"in",process.cwd());try{let{stdout:e,stderr:a}=await g("npx",["create-next-app@latest",c,"--typescript","--eslint","--use-pnpm","--tailwind","--app","--no-src-dir","--import-alias","@/*"],{stdio:"inherit"});e&&n.log(e),a&&n.error(a),n.log("Created Next.js app")}catch(e){throw n.error("Error creating Next.js app:",e),e}}async function A(t){let{authType:e,authProviders:a,miscPackages:i,db:p}=t;h=t.orm,n.log("Running Kirimase init");try{let{stdout:s,stderr:o}=await g("npx",["@alephmatic/kirimase@latest","init","--has-src-folder","false","--package-manager","pnpm","--component-lib","shadcn-ui","--orm",h,"--db",p,"--include-example","false","--auth",e,"--auth-providers",...a,"--misc-packages","trpc",...i],{stdio:"inherit",cwd:`./${c}`});s&&n.log(s),o&&n.error(o),n.log("Completed Kirimase init")}catch(s){throw n.error("Error for kirimase init:",s),s}}async function O(t){let{table:e,belongsToUser:a,index:i}=t,p=["model","trpc_route","views_and_components"],s=h==="drizzle"?t.fields:t.fields.map(o=>({...o,type:N[o.type]}));n.log("Running Kirimase generate");try{let{stdout:o,stderr:b}=await g("npx",["@alephmatic/kirimase@latest","generate","--resourceTypes",p.join(","),"--table",e,"--fields",JSON.stringify(s),"--belongsToUser",a?"yes":"no","--index",i||""],{stdio:"inherit",cwd:`./${c}`});o&&n.log(o),b&&n.error(b),n.log("Completed Kirimase generate")}catch(o){throw n.error("Error for kirimase generate:",o),o}}function T(){return{createNextApp:{function:async e=>{try{return await z(e),{success:!0}}catch(a){throw n.error("Error createNextApp app.","Args:",JSON.stringify(e,null,2),"Error:",a),a}},name:"createNextApp",description:"Create a Next.js app with TypeScript and Tailwind CSS.",parse:e=>m.parse(JSON.parse(e)),parameters:y},kirimaseInit:{function:async e=>{try{return await A(e),{success:!0}}catch(a){throw n.error("Error kirimaseInit app.","Args:",JSON.stringify(e,null,2),"Error:",a),a}},name:"kirimaseInit",description:"Initialize Kirimase. Must be run before using kirimaseGenerate. This adds authentication, shadcn/ui components and other functionality to the project.",parse:e=>u.parse(JSON.parse(e)),parameters:x},kirimaseGenerate:{function:async e=>{try{return await O(e),{success:!0}}catch(a){throw n.error("Error kirimaseGenerate.","Args:",JSON.stringify(e,null,2),"Error:",a),a}},name:"kirimaseGenerate",description:"Generate models, api routes, and views with Kirimase.",parse:e=>f.parse(JSON.parse(e)),parameters:w}}}async function S(t){if(!process.env.OPENAI_API_KEY){d.error("Please set OPENAI_API_KEY as an environment variable.");return}d.log("Generating code with AI...");let i=await new C().beta.chat.completions.runFunctions({model:"gpt-4-1106-preview",messages:[{role:"system",content:`You are an AI that builds full-stack apps for users.'
elie222 commented 11 months ago

Thanks for flagging! Affecting a lot of people. Need to take a look over the weekend.