Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server is not a constructor V.1.41 #56

Open
TheSman122333 opened this issue Feb 9, 2024 · 21 comments
Open

Server is not a constructor V.1.41 #56

TheSman122333 opened this issue Feb 9, 2024 · 21 comments
Assignees
Labels
bug Something isn't working

Comments

@TheSman122333
Copy link

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 TheSman122333 added the bug Something isn't working label Feb 9, 2024
@TheSman122333
Copy link
Author

@Notplayingallday383

@Notplayingallday383
Copy link
Member

Notplayingallday383 commented Feb 10, 2024

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

@TheSman122333
Copy link
Author

Yes, I still get the error.

@TheSman122333
Copy link
Author

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
Copy link
Member

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

@TheSman122333
Copy link
Author

I think it is a newer version

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

@Notplayingallday383

@TheSman122333
Copy link
Author

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

@Notplayingallday383
Copy link
Member

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
Copy link
Author

TheSman122333 commented Feb 12, 2024

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
Copy link
Author

@Notplayingallday383

@Notplayingallday383
Copy link
Member

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
Copy link
Author

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
Copy link
Author

on this line

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

@Notplayingallday383

@Notplayingallday383
Copy link
Member

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
Copy link
Author

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
Copy link
Member

Notplayingallday383 commented Feb 26, 2024

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
Copy link
Author

/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
Copy link
Member

Copy package.json too

@TheSman122333
Copy link
Author

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
Copy link
Author

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants