TerbiumOS / webOS

TerbiumOS web is a web os packed with features, with new updates every so often
Apache License 2.0
132 stars 696 forks source link

Server is not a constructor V.1.41 #56

Open TheSman122333 opened 4 months ago

TheSman122333 commented 4 months ago

const bare = new Server('/bare/', ''); ^

TypeError: Server is not a constructor at file:///home/runner/TeemingArcticPorts/index.mjs:6:15 at ModuleJob.run (node:internal/modules/esm/module_job:193:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:530:24) at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)

OS version 1.41 I think, I made a fork of terbium a looong time ago, and I recovered it. Using Opera GX/Chrome

The issue is that there is no output in the repls saying that server isnt a constructor, but in 1.41, and 1.42 it uses the code that gives the error

this code: import Server from 'bare-server-node'; import http from 'http'; import nodeStatic from 'node-static';

const bare = new Server('/bare/', ''); const serve = new nodeStatic.Server('static/');

const server = http.createServer();

server.on('request', (request, response) => { if (bare.route_request(request, response)) return true; serve.serve(request, response); });

server.on('upgrade', (req, socket, head) => { if(bare.route_upgrade(req, socket, head))return; socket.end(); });

server.listen(process.env.PORT || 6969);

TheSman122333 commented 4 months ago

@Notplayingallday383

Notplayingallday383 commented 4 months ago

Did you run npm i? You need to install the dependencies first in order to use terbium

TheSman122333 commented 4 months ago

Yes, I still get the error.

TheSman122333 commented 4 months ago

index.mjs

import { Server } from "@tomphttp/bare-server-node";
         ^^^^^^
SyntaxError: Named export 'Server' not found. The requested module '@tomphttp/bare-server-node' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@tomphttp/bare-server-node';
const { Server } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)

Node.js v18.12.1
Notplayingallday383 commented 4 months ago

If your using the latest version which includes the latest bare version server was deprecated and replaced with createBareServer

TheSman122333 commented 4 months ago

I think it is a newer version

    "@tomphttp/bare-server-node": "^2.0.1",

@Notplayingallday383

TheSman122333 commented 4 months ago

btw this is a very old fork, probably even before v1.41, but maybe v.1.41

Notplayingallday383 commented 4 months ago

ok so since ur using a newer version of Bare, the "server" function has been deprecated in place for { createBareServer } so in your backend just change the line: import Server from 'bare-server-node'; to: import { createBareServer } from 'bare-server-node' that should work

TheSman122333 commented 4 months ago

I changed the code to this:

import { createBareServer } from 'bare-server-node';
import http from 'http';
import nodeStatic from 'node-static';

const bare =  new createBareServer('/bare/', '');
const serve = new nodeStatic.Server('static/');

const server = http.createServer();

server.on('request', (request, response) => {
    if (bare.route_request(request, response)) return true;
    serve.serve(request, response);
});

server.on('upgrade', (req, socket, head) => {
    if(bare.route_upgrade(req, socket, head))return;
    socket.end();
});

server.listen(process.env.PORT || 6969);

and nothing is happening, the ouput console is empty.

TheSman122333 commented 4 months ago

@Notplayingallday383

Notplayingallday383 commented 4 months ago

Ok that means it should be working cus that code doesn’t have a console.log that states the server is ready so try visiting http://localhost:6969 and seeing if it worked

TheSman122333 commented 4 months ago

nevermind, i get this error

    init.logErrors ??= false;
                   ^

TypeError: Cannot create property 'logErrors' on string ''
    at new createBareServer (/home/runner/teemingarcticports/node_modules/bare-server-node/dist/createServer.js:42:20)
    at file:///home/runner/teemingarcticports/index.mjs:6:15
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)

Node.js v18.12.1
TheSman122333 commented 4 months ago

on this line

const bare =  new createBareServer('/bare/', '');

@Notplayingallday383

Notplayingallday383 commented 4 months ago

on this line

const bare =  new createBareServer('/bare/', '');

@Notplayingallday383

Sorry I forgot to respond but the ,'' I dont think works. So I would suggest changing it to: const bare = createBareServer('/bare/');

TheSman122333 commented 4 months ago

import { createBareServer } from 'bare-server-node'; import http from 'http'; import nodeStatic from 'node-static';

const bare = createBareServer('/bare/'); const serve = new nodeStatic.Server('static/');

const server = http.createServer();

server.on('request', (request, response) => { if (bare.route_request(request, response)) return true; serve.serve(request, response); });

server.on('upgrade', (req, socket, head) => { if(bare.route_upgrade(req, socket, head))return; socket.end(); });

server.listen(process.env.PORT || 6969); its giving

file:///home/runner/teemingarcticports/index.mjs:12 if (bare.route_request(request, response)) return true; ^

TypeError: bare.route_request is not a function at Server. (file:///home/runner/teemingarcticports/index.mjs:12:14) at Server.emit (node:events:513:28) at Server.emit (node:domain:489:12) at parserOnIncoming (node:_http_server:1068:12)

Node.js v18.12.1

Notplayingallday383 commented 4 months ago

Alright since that isn’t working just copy and paste the new backend code instead of the really old one which can be found: https://github.com/TerbiumOS/webOS/blob/main/index.js

TheSman122333 commented 4 months ago

/home/runner/teemingarcticports/index.js:1 import { createBareServer } from "@tomphttp/bare-server-node"; ^^^^^^

SyntaxError: Cannot use import statement outside a module Hint: hit control+c anytime to enter REPL.

new code

Notplayingallday383 commented 4 months ago

Copy package.json too

TheSman122333 commented 2 months ago

I'm sorry, I was locked out of my github acc for a while, can we meet on discord or something and debug it? It works but I get this error Error: ENOENT: no such file or directory, stat '/home/runner/teemingarcticports/static/sw/hvtrs8/-ymuvu`e,cmm'

TheSman122333 commented 2 months ago

I saw someone had an error and it was with service workers, but I want to be able to customize my apps not just have the defaults, if it is possible to change it and bypass repls blocking, I will try to use the newest version.

Notplayingallday383 commented 2 months ago

I'm sorry, I was locked out of my github acc for a while, can we meet on discord or something and debug it? It works but I get this error Error: ENOENT: no such file or directory, stat '/home/runner/teemingarcticports/static/sw/hvtrs8/-ymuvu`e,cmm'

Yeah sure