HeadlessX icon indicating copy to clipboard operation
HeadlessX copied to clipboard

[Bug]: Failed to install the new V2

Open manuman94 opened this issue 10 months ago • 8 comments

Preliminary Checks

  • [x] I have searched existing issues for similar problems
  • [x] I have read the troubleshooting documentation
  • [x] I am using a supported version of HeadlessX

HeadlessX Version

2.0.0

Installation Method

npm install

Environment

Ubuntu 22

Bug Description

When running npm build asks for an environment variable throwing this error:

manuman94@homer:~/services/HeadlessX$ pnpm install
Scope: all 3 workspace projects
Lockfile is up to date, resolution step is skipped
Packages: +1052
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 1052, reused 1052, downloaded 0, added 1052, done

devDependencies:
+ concurrently 9.2.1
+ cross-env 10.1.0
+ only-allow 1.2.2

backend postinstall$ npx camoufox-js fetch && prisma generate
│ npm warn Unknown env config "auto-install-peers". This will stop working in the next major version of npm.
│ npm warn Unknown env config "shamefully-hoist". This will stop working in the next major version of npm.
│ npm warn Unknown project config "auto-install-peers". This will stop working in the next major version of npm.
│ npm warn Unknown project config "shamefully-hoist". This will stop working in the next major version of npm.
│ Camoufox binaries up to date!
│ Current version: v135.0.1-beta.24
│ Failed to load config file "/home/manuman94/services/HeadlessX/backend" as a TypeScript/JavaScript module. Error: PrismaConfigEnvError: Cannot resolve environment variable: DATABAS…
└─ Failed in 4.4s at /home/manuman94/services/HeadlessX/backend
 ELIFECYCLE  Command failed with exit code 1.

In the documentation is stated to use Supabase, but it would be nice to add it to the prerequisites of the quickstart. Is it possible to use self-hosted PostgreSQL?

Plus, I found a couple of issues while launching it in my Ubuntu server:

  • The first one is that the PORT environment variable is not taken into account because both frontend and backend have the port hardcoded in their package.json (or at least I couldn't make it work 😅)
  • Then when I launch the backend I get this error:
manuman94@homer:~/services/HeadlessX/backend$ npm run dev
npm warn Unknown project config "auto-install-peers". This will stop working in the next major version of npm.
npm warn Unknown project config "shamefully-hoist". This will stop working in the next major version of npm.

> [email protected] dev
> tsx watch src/server_entry.ts

/home/manuman94/services/HeadlessX/backend/src/env.ts:7
const envPath = path.resolve(__dirname, '..', '.env');
                             ^

ReferenceError: __dirname is not defined in ES module scope
    at <anonymous> (/home/manuman94/services/HeadlessX/backend/src/env.ts:7:30)
    at ModuleJob.run (node:internal/modules/esm/module_job:413:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:660:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)

Node.js v24.13.0

(and I got this one when trying to Dockerize the application too, so this one is not related with my system)

Nice job man, it looks really cool! I can't wait to try it!

Expected Behavior

Build works successfully and the user is able to choose ports for frontend and backend. Documentation states the actual requisites too.

Actual Behavior

Build fails and documentation is a bit confusing regarding setting up the project.

Steps to Reproduce

Just follow the Quickstart steps in the README.md

Error Logs


Configuration


Severity

Critical (application crashes, security vulnerability)

Browser Context

None

Additional Context

No response

Contribution

  • [ ] I am willing to help fix this bug
  • [x] I can provide additional testing
  • [ ] I can help with documentation updates

manuman94 avatar Jan 29 '26 02:01 manuman94

Hi there,

for docs: https://headlessx.saify.me/docs/introduction I am trying to Solve this ASAP,

Best Regards, Saifullah

saifyxpro avatar Jan 29 '26 02:01 saifyxpro

Okay! No worries, if we have updated documentation that's enough for now!

I suggest you to modify the README and add that link with a warning explaining that; it will save you a lot of issues hehe :)

Thanks again!

manuman94 avatar Jan 29 '26 02:01 manuman94

wait for fix

saifyxpro avatar Jan 29 '26 02:01 saifyxpro

Hey @JeremyDuc! 👋

Thanks for reporting this! I’ve pushed a fix that addresses all the issues you encountered. Here’s what was updated:

pnpm Build Successful:

Image

📋 Updated Installation Steps

git clone https://github.com/saifyxpro/HeadlessX.git
cd HeadlessX

# 1. Copy and configure environment variables
cp .env.example backend/.env
# Edit backend/.env and set your DATABASE_URL

# 2. Install dependencies
pnpm install

# 3. Set up the database
pnpm db:push

# 4. Start the development server
pnpm dev

The README has also been updated with clearer prerequisites and database setup instructions.

Alternatively, you can use the scripts in the /scripts directory to get started.

Let me know if you run into any other issues! 🚀

saifyxpro avatar Jan 29 '26 02:01 saifyxpro

Wow! That was fast! My previous issues were solved.

But now I get CORS issues probably because CORS is disabled or has strict rules (it happens when frontend tries to contact backend triggering:

Access to fetch at 'http://mydomain.com:3053/api/website/stream' from origin 'http://mydomain.com:3002' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Maybe you could use NEXT_PUBLIC_API_URL (as we use the same .env file) to add it to the CORS rules.

What do you think?

Thanks!

manuman94 avatar Jan 29 '26 02:01 manuman94

I see it's limited here to only work with 'http://localhost:3000' and 'http://127.0.0.1:3000'

manuman94 avatar Jan 29 '26 02:01 manuman94

And careful with hardcoded ports ;)

manuman94 avatar Jan 29 '26 03:01 manuman94

Hey @manuman94! 👋 Great catch! I've just pushed a fix for the CORS issue.

🔧 What was fixed:

The CORS configuration now dynamically reads from environment variables:

// app.ts - CORS now supports custom origins
const corsOrigins = [
  'http://localhost:3000',
  'http://127.0.0.1:3000',
];

// Add FRONTEND_URL if configured
if (process.env.FRONTEND_URL) {
  corsOrigins.push(process.env.FRONTEND_URL);
}

📋 To fix on your deployment:

Add this to your backend/.env:

# Add your frontend URL for CORS
FRONTEND_URL=http://mydomain.com:3002

Restart the backend and CORS should work for your custom domain! 🚀

Let me know if you run into anything else!

saifyxpro avatar Jan 29 '26 03:01 saifyxpro