lane711 / sonicjs

SonicJs Headless CMS - Blazing Fast Headless CMS built on Cloudflare Workers. 100% Javascript Based
https://sonicjs.com
878 stars 117 forks source link

Can't Install #107

Closed aereaco closed 2 years ago

aereaco commented 2 years ago

Just tried to build and start project on a fresh install of Debian 11 and tried under Windows 11 but setup fails. Please list the actual requirements to get things up and going such as node.js version, python, yarn, database or whatever else is unique to your build environment because it's not as simple as you claimed to be in documentation or readme.

lane711 commented 2 years ago

Hi, the only hard requirement is Node v14.17.5 or later. http://sonicjs.herokuapp.com/docs#collapse142

I'll do some additional sanity checking asap, but if you can please provide more details on the specific error messages, that would be greatly appreciated.

Thanks, Lane

aereaco commented 2 years ago

PS C:\Users\vyoung\Projects\sonicjs> npm i -force npm WARN using --force I sure hope you know what you are doing. added 3 packages from 7 contributors and audited 884 packages in 4.488s

71 packages are looking for funding run npm fund for details

found 32 vulnerabilities (1 low, 18 moderate, 13 high) run npm audit fix to fix them, or npm audit for details PS C:\Users\vyoung\Projects\sonicjs> npm start

sonicjs@0.5.3 start C:\Users\vyoung\Projects\sonicjs node server.js

C:\Users\vyoung\Projects\sonicjs\server\boot\routes.js:236 if (page.data?.title === "Not Found") { ^

SyntaxError: Unexpected token '.' at wrapSafe (internal/modules/cjs/loader.js:915:16) at Module._compile (internal/modules/cjs/loader.js:963:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) at Object. (C:\Users\vyoung\Projects\sonicjs\server.js:22:16) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! sonicjs@0.5.3 start: node server.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the sonicjs@0.5.3 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\vyoung\AppData\Roaming\npm-cache_logs\2022-01-17T16_47_39_487Z-debug.log PS C:\Users\vyoung\Projects\sonicjs>

aereaco commented 2 years ago

Hi, the only hard requirement is Node v14.17.5 or later. http://sonicjs.herokuapp.com/docs#collapse142

I'll do some additional sanity checking asap, but if you can please provide more details on the specific error messages, that would be greatly appreciated.

Thanks, Lane

What environments have you tested and built in? Are you deploying this only in heroku? You definitely need python for some of the modules because without it npm install will produce more errors, please stop trying to make this sound easy and give proper requirements. Not every environment has python pre-installed, Please at least list Python as a requirement as well. Please list the environment you have tested in. What OS or distro are you deploying this under? please list the exact OS, packages & versions and build dependencies such as python and what ever else thats installed on a system this this project actually works under. Just cloning repo and npm install & start isn't working because it's expecting something else in the environment which for whatever reason you are failing to mention. Please share specific details of your environment so we can at least mimic setup.

aereaco commented 2 years ago

PS C:\Users\vyoung\Projects\sonicjs> npm i @popperjs/core npm WARN deprecated source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated npm WARN deprecated har-validator@5.1.5: this library is no longer supported npm WARN deprecated mimelib@0.3.1: This project is unmaintained npm WARN deprecated mailparser@0.6.2: Mailparser versions older than v2.3.0 are deprecated npm WARN deprecated tooltip.js@1.3.3: Tooltip.js is not supported anymore, please migrate to tippy.js npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 npm WARN deprecated uuid@3.3.2: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm WARN deprecated uglify-es@3.3.9: support for ECMAScript is superseded by uglify-js as of v3.13.0 npm WARN deprecated node-pre-gyp@0.11.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future npm WARN deprecated sendgrid@5.2.3: Please see v6.X+ at https://www.npmjs.com/org/sendgrid npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap. npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1 npm WARN deprecated pace-progress@1.0.2: Disclaimer, We no longer use this library internally and are focusing our efforts on open sourcing and maintaining projects that we do use and can meaningfully contribute to. Sorry for any frustrations with this project (we're happy to link to any fork that has an excited, commited maintainer). npm WARN deprecated flag-icon-css@3.5.0: The project has been renamed to flag-icons

added 768 packages, and audited 769 packages in 2m

89 packages are looking for funding run npm fund for details

3 high severity vulnerabilities

To address all issues (including breaking changes), run: npm audit fix --force

Run npm audit for details. PS C:\Users\vyoung\Projects\sonicjs> npm start

sonicjs@0.5.3 start node server.js

C:\Users\vyoung\Projects\sonicjs\server\boot\routes.js:236 if (page.data?.title === "Not Found") { ^

SyntaxError: Unexpected token '.' at wrapSafe (internal/modules/cjs/loader.js:915:16) at Module._compile (internal/modules/cjs/loader.js:963:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) at Object. (C:\Users\vyoung\Projects\sonicjs\server.js:22:16) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) PS C:\Users\vyoung\Projects\sonicjs>

aereaco commented 2 years ago

Something is broke in code or not all dependencies are properly installed. I had to modify your routes.js code to get project to run. Following comment contains modified routes.js file. I had to comment out part of code to get project to at least run.

aereaco commented 2 years ago

// var loopback = require("loopback"); var emitterService = require("../services/emitter.service"); var globalService = require("../services/global.service"); var cacheService = require("../services/cache.service"); var urlService = require("../services/url.service"); urlService.startup(); var pageBuilderService = require("../services/page-builder.service"); var adminService = require("../services/admin.service"); var dataService = require("../services/data.service"); dataService.startup(); var moduleService = require("../services/module.service"); var formService = require("../services/form.service"); var menuService = require("../services/menu.service"); var mediaService = require("../services/media.service"); var siteSettingsService = require("../services/site-settings.service"); var themeSettingsService = require("../services/theme-settings.service"); var contentService = require("../services/content.service"); contentService.startup(); var cssService = require("../services/css.service"); cssService.startup(); var assetService = require("../services/asset.service"); var userService = require("../services/user.service"); var authService = require("../services/auth.service"); var dalService = require("../services/dal.service"); var backupService = require("../services/backup.service"); var backupRestoreService = require("../services/backup-restore.service");

var helperService = require("../services/helper.service"); var sharedService = require("../services/shared.service"); var breadcrumbsService = require("../services/breadcrumbs.service"); var mixPanelService = require("../modules/mixpanel/services/mixpanel-main-service"); var _ = require("underscore"); const ShortcodeTree = require("shortcode-tree").ShortcodeTree; let ShortcodeFormatter = require("shortcode-tree").ShortcodeFormatter;

const path = require("path"); var cors = require("cors"); const chalk = require("chalk"); const log = console.log; const url = require("url"); const fileService = require("../services/file.service"); var pageLoadedCount = 0;

var frontEndTheme = ${process.env.FRONT_END_THEME};

exports.loadRoutes = async function (app) { authService.startup(app); adminService.startup(app); formService.startup(app); backupService.startup(app); backupRestoreService.startup(app);

let page = ""; let adminPage = "";

(async () => { await dalService.startup(app); await cacheService.startup(); await moduleService.startup(app); await menuService.startup(); await mediaService.startup(); await siteSettingsService.startup(); await themeSettingsService.startup(); await userService.startup(app); await assetService.startup(); await pageBuilderService.startup(app); await pageBuilderService.startup(app);

await emitterService.emit("startup", { app: app });

//load catch-all last
this.loadRoutesCatchAll(app);

await emitterService.emit("started", { app: app });

})();

app.get("*", async function (req, res, next) { globalService.AccessToken = "todo-access-token";

if (req.session) {
  req.session.nowInMinutes = Math.floor(Date.now() / 60e3);
}

next();

});

app.get("/hbs", async function (req, res) { res.render("home"); });

app.get("/nested-forms-list*", async function (req, res) { let contentTypesRaw = await dataService.contentTypesGet(); let contentTypes = contentTypesRaw.map(function (contentType) { return { id: contentType.systemId, type: "form", title: contentType.title, }; }); let sorted = .sortBy(contentTypes, "title");

res.send(sorted);

});

app.get("/form/*", async function (req, res) { let moduleSystemId = req.path.replace("/form/", ""); let contentType = await dataService.contentTypeGet( moduleSystemId, req.sessionID ); let form = await formService.getFormJson(contentType, req.sessionID); res.send(form); });

app.get("/zsandbox", async function (req, res) { let data = {}; res.render("sandbox", { layout: "blank.handlebars", data: data }); });

app.get("/theme1", async function (req, res) { let data = {}; res.render("sandbox", { layout: theme, data: data }); });

app.get("/theme2", async function (req, res) { let data = {}; res.render("sandbox", { layout: "theme2.handlebars", data: data }); });

app.get("/admin/sandbox", async function (req, res) { let data = {}; res.render("sandbox", { layout: "admin.handlebars", data: data }); });

app.get("/css/generated.css", async function (req, res) { res.set("Content-Type", "text/css"); let css = await cssService.getGeneratedCss(); res.send(css); });

app.post("/dropzone-upload", async function (req, res) { console.log("dropzone-upload req.files.file", req.files.file); await fileService.uploadWriteFile(req.files.file, req.sessionID); res.sendStatus(200); });

app.post("/form-submission", async function (req, res) { let payload = req.body.data.data ? req.body.data.data : undefined;

if (payload) {
  let options = { data: payload, sessionID: req.sessionID };

  await emitterService.emit("afterFormSubmit", options);
}

res.sendStatus(200);

});

app.post("*", async function (req, res, next) { await emitterService.emit("postBegin", { req: req, res: res });

if (!req.isRequestAlreadyHandled) {
  next();
}

}); };

exports.loadRoutesCatchAll = async function (app) { app.get(/^[^.]*$/, async function (req, res, next) { await emitterService.emit("requestBegin", { req: req, res: res });

if (req.isRequestAlreadyHandled) {
  //modules can set the req.isRequestAlreadyHandled to true if they
  //have already fully handled the request including the response.
  return;
}

var ip = req.headers["x-forwarded-for"] || req.connection.remoteAddress;

//for modules css/js files
if (
  (req.url.endsWith(".css") || req.url.endsWith(".js")) &&
  req.url.startsWith("/modules/")
) {
  let cssFile = path.join(__dirname, "..", req.url);
  // res.set('Content-Type', 'text/css');
  res.sendFile(cssFile);
  return;
}

if (
  req.url.startsWith("/graphql") ||
  req.url.startsWith("/login") ||
  req.url.startsWith("/register") ||
  req.url.startsWith("/api") ||
  req.url.endsWith(".css") ||
  req.url.endsWith(".html") ||
  req.url.endsWith(".ico") ||
  req.url.endsWith(".map") ||
  req.url.endsWith(".jpg") ||
  req.url.endsWith(".png") ||
  req.url.endsWith(".svg") ||
  req.url.endsWith(".txt") ||
  req.url.endsWith(".js") ||
  req.url.indexOf(".js?") > -1 ||
  req.url.indexOf("fonts") > -1 ||
  req.url.indexOf(".woff") > -1
) {
  return next();
}

if (process.env.MODE == "production") {
  console.log(`serving: ${req.url}`);
}

let isAuthenticated = await userService.isAuthenticated(req);
globalService.setAreaMode(false, true, isAuthenticated);

//lookup which module should handle this request
// console.log("processing", req.url);
let urlKey = await urlService.getUrl(req.url);
// console.log("urlKey", urlKey);

//replace this will 

var page = {};
req.urlKey = urlKey;
var processUrlOptions = { req, res, urlKey, page };

await emitterService.emit("processUrl",processUrlOptions);
page = processUrlOptions.page;

// return;

// if (page.data?.title === "Not Found") { // // res.render("404", page); // res.render(front-end/${frontEndTheme}/layouts/404, { // layout: front-end/${frontEndTheme}/${frontEndTheme}, // });

// return; // }

await emitterService.emit("preRenderTemplate", (options = { page, req }));

page.data.id = page.id;
page.data.sessionID = req.sessionID;
page.data.themeSettings.bootstrapToggleMiddle  = page.data.themeSettings.bootstrapVersion == 4 ? '': 'bs-';

res.render(`front-end/${frontEndTheme}/layouts/main`, {
  layout: `front-end/${frontEndTheme}/${frontEndTheme}`,
  data: page.data,
});

req.pageLoadedCount = pageLoadedCount;
if (pageLoadedCount < 1) {
  await emitterService.emit("firstPageLoaded", (options = { req }));
}
pageLoadedCount++;

await emitterService.emit("postPageRender", (options = { page, req }));

}); };

lane711 commented 2 years ago

I get the same error as you do if I run on node 12, what version on you using?

aereaco commented 2 years ago

I've tried this under 12, 14, 16, 17

aereaco commented 2 years ago

if you comment out lines 236 - 243 of /server/boot/routes.js the project will at least run.

// if (page.data?.title === "Not Found") { // // res.render("404", page); // res.render(front-end/${frontEndTheme}/layouts/404, { // layout: front-end/${frontEndTheme}/${frontEndTheme}, // }); // // return; // }

lane711 commented 2 years ago

I'll do some additional testing on Windows and report back ASAP. I have not tested on Windows lately. Thanks for posting the details above

aereaco commented 2 years ago

If you comment out what was mentioned the project will run and you can reach admin side of app but not front end of app. If you keep routes.js unmodified app will not start at all. I'll try to see if I can replicate issue under Debian 11. What OS are you using please share? I would like for you to share the details of your environment in which you have successfully got this working so we can get this working.

lane711 commented 2 years ago

I am using MacOS but have hundreds of installs across other OS. This might be the result of a recent code update - will investigate ASAP

lane711 commented 2 years ago

after changing your version of node, did you delete your node_modules folder and rerun npm i?

aereaco commented 2 years ago

With each install attempt I completely deleted the project folder and re-cloned with git from github

aereaco commented 2 years ago

I have tried running this now under Debian, Ubuntu, & Windows to no avail.

lane711 commented 2 years ago

I was able to reproduce your issue. It appears that it happens when using the latest version of npm. I should have this fixed in the next couple days but in the meantime you could use "n" package manager to downgrade to and earlier version of node like 14.x which includes the older version of npm. hth

lane711 commented 2 years ago

Actually I was able to update the lock file, so you should be good if you get latest from master and try again.