#openai movie idea generator problem
68 messages · Page 1 of 1 (latest)
The solution is to use npm run dev or npm start, you're not supposed to use live server when you're importing packages like openai since you're relying on node.js
and when you upload to netlify, make sure to include package.json so it knows to install the required packages
@cosmic cobalt it is included cuz i upload the entire folder like with every other app and its not working when i upload it this is my package.json from the scrim
Did you install openai via node?
Yes
yep
Do this, send the github link of the project and I'll take a look
sec
@kindred path import { Configuration, OpenAIApi } from "../openai"; do this and see if it fixes it
kk, just wanted to see smth
ok thanks for trying to help btw
const { Configuration, OpenAIApi } = require("openai");
if i do this the error changes in require is undefined
look
even in the dev thing
ok wait im uploading it to netlify with a key
the key is good now and i still get the 404
ok im gonna try something
even on netlify
idk, sorry x)
idk what to do 😦
Try:
import { Configuration, OpenAIApi } from "openai"
require is common js import syntax and cannot be used with es6 imports.
I haven't been through this project, so the import may brake depending on if openai exports those named functions.
Also, try to cd into the project root and run npm install again and see if it helps.
The reason it's likely asking for a relative path is because the bundler isn't handling the node module imports correctly. Which also makes me wonder if vite is actually installed.
If the previous import doesn't work after installing again, try changing the import from:
from "openai"
To:
from "./node_modules/openai"
And see if it fixes it. If it does, I suspect something is wrong with the module bundler for some reason.
@oak ingot i get this error if i use .node_modules/openai
Ok, one moment... but at least we know that the bundler isn't working correctly. Did you try to reinstall?
i did npm install again
And did you try with just import openapi before using node modules path?
So it's working now?
its working with npm start and npm run dev, just as before but i can't put it on netlify
cuz i get that error
Ok, so that error is only from a netlify deploy but works fine locally?
yes, it doesn't work only when i try to put it there or i think on any hosting site
And for the scripts that you have run for your deploy, what did you tell netlify to use?
how do i do that? i just press on deploy and thats it
I've never used netlify, but I have used vercel and they have you use your own commands when deploying. Netlify may have a different automation process. I may not be able to help you just this minute.... I'm at work right now putting a dashboard back in a vehicle. When I get home in a little while I'll fork your repo and see if I can deploy it to netlify to find out where the error is. So please be patient with me!
@oak ingot Thank you so much for trying to help me, if nothing works i can try vercel too, netlify was recomended from scrimba thats why i used it
No problem! I haven't done this project so it will be new to me. I'll have to go generate an api key for openai and do it the way you are trying. So it will be in line with what you are already doing rather than having to shift to something else. But we will figure it out.
@oak ingot thank you for helping me, im trying to upload it to vercel now and see if it works
i tried to upload it to vercel and i get this error
@kindred path The deploy seems to work well for me using your repo. Here is a live site of your project https://fancy-malabi-e6b85a.netlify.app/. I don't really know why it is doing what it is doing. Can you go to site setting for your deploy and and check under continuous deploy and take a screenshot of your "Build Settings"? Also, I noticed that your loading image is broken in deploy.
I created a pull request to your repo, I removed the node_modules folder from the repo because it is not needed. I changed a couple of things. If you need any help with it, I will do my best. I just get busy during the day. Though I can be pretty helpful in the evenings. I left a pretty sizable comment on the pull request.
@oak ingot so i should stop the export of the node_modules ? and about the deploy on netlify, i linked netlify with github and it just took the repository from there and deployed it, i think the problem was that it didn't had any build settings before, its working now, thank you so so much, the only way i could change the deploy settings was by linking my github account and it took the project from there, You are the best, is it ok if i add you on discord? 🙂
@oak ingot i read everything from you pull request and thanks for the information, the api key thing about security, i am aware of that but it's just a small project for my portofolio nothing too bad there i guess, the key is using free credits anyway, but thanks for the headsup
One question i tried just to see if it works to link another project from github directly and i get an error that an html is missing, but it works fine when i deploy it from my pc directly, should i just upload it normaly or
@oak ingot sadly the app will not work from now on cuz the api key is revoked, i used the free credits, but thank you so much for your help

@kindred path you typically don't push node modules to a repo. Every dependency that someone would need is stored in the package.json. All they would have to do is run npm install. Node modules would be unnecessary. And yes, you are more than welcome to add me.
As far as your other project, I'm not sure. I'm not sure what the error for html missing means. I'd have to see it.
I'm sorry the app stopped working. You could always sign up for a different free email address and use that email address for another round of free credits if you wanted 😀.
Also, if you accidentally push your api key to github, github scans for openai api keys and reports them to openai. Openai, in turn, revokes the api key. It may be as simple as creating a new key and not pushing it to github.
@oak ingot thank you for your help, i'll finish the openai scrim and than i'll start to do something else cuz i don't wanna add something to my portofolio that will stop working when the api key will be revoked, thank you so much for your help once again