Logic in config.js breaks EVERYTHING
See original GitHub issuePlatform: ANY
Node Version: ANY
MagicMirror Version: v2.
Description: Adding ANY logic to config.js gives the error message as if a config does not exist. The “config:check” script still passes.
Steps to Reproduce: Add any logic/requires to the top of config.js. The following line breaks it:
var fs = require("fs");
Expected Results: I expect to be able to add logic to the config.js file to load settings off disk from a JSON file in the same directory.
Actual Results: The “Please create a config file” screen appears.
Configuration:
/* Magic Mirror Config Sample
*
* By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed.
*
* For more information how you can configurate this file
* See https://github.com/MichMich/MagicMirror#configuration
*
*/
var fs = require("fs");
var config = {
address: "localhost", // Address to listen on, can be:
// - "localhost", "127.0.0.1", "::1" to listen on loopback interface
// - another specific IPv4/6 to listen on a specific interface
// - "", "0.0.0.0", "::" to listen on any interface
// Default, when address config is left out, is "localhost"
port: 8080,
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], // Set [] to allow all IP addresses
// or add a specific IPv4 of 192.168.1.5 :
// ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.1.5"],
// or IPv4 range of 192.168.3.0 --> 192.168.3.15 use CIDR format :
// ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.3.0/28"],
language: "en",
timeFormat: 24,
units: "metric",
modules: [
{
module: "alert",
},
{
module: "updatenotification",
position: "top_bar"
},
{
module: "clock",
position: "top_left"
},
{
module: "calendar",
header: "US Holidays",
position: "top_left",
config: {
calendars: [
{
symbol: "calendar-check",
url: "webcal://www.calendarlabs.com/templates/ical/US-Holidays.ics"
}
]
}
},
{
module: "compliments",
position: "lower_third"
},
{
module: "currentweather",
position: "top_right",
config: {
location: location.location,
locationID: "", //ID from http://bulk.openweathermap.org/sample/; unzip the gz file and find your city
appid: "YOUR_OPENWEATHER_API_KEY"
}
},
{
module: "weatherforecast",
position: "top_right",
header: "Weather Forecast",
config: {
location: location.location,
locationID: "5128581", //ID from https://openweathermap.org/city
appid: "YOUR_OPENWEATHER_API_KEY"
}
},
{
module: "newsfeed",
position: "bottom_bar",
config: {
feeds: [
{
title: "New York Times",
url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml"
}
],
showSourceTitle: true,
showPublishDate: true
}
},
]
};
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {module.exports = config;}
Additional Notes: This is a VERY straight forward reproduction case that cripples the configuration capabilities beyond what anyone should consider acceptable. If we can’t add logic to the config.js file, why is it not just a JSON file?
Issue Analytics
- State:
- Created 5 years ago
- Comments:30 (2 by maintainers)
Top Results From Across the Web
Override files globbing logic breaks with --config · Issue #11558
I think our intention is that all paths are relative to the file which the path is written. But if a path is...
Read more >Using external babel configuration breaks node/react app
My goal is to have an app that runs both npm run dev and npm test and not one or the other. At...
Read more >Line and page breaks in a score set in Logic Pro - Apple Support
Page breaks are saved with the project. For information, see Add page and line break symbols to a score in Logic Pro.
Read more >ESLint's new config system, Part 2: Introduction to flat config
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Content Configuration - Tailwind CSS
This guide covers everything you need to know to make sure Tailwind generates all of the CSS needed for your project. . Configuring...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Understood at this point. I had originally (before actually looking though the project source) figured it was a server only or even a “build” time file. I was introduced to the project pretty late that night by the roommate who had brought up the fact there wasn’t an easy way to do autolocation on the gifts he was going to be giving to people in unknown locations who would not have the skills to do the configuration themselves.
I might become a regular contributor here after the pleasant experience and quick help from you guys 😃
As a fun little thing, I was thinking through other ways a project like this could be approached and whipped up my own little “clone” if you are interested in some “new” ideas for a v3 architecture: https://github.com/jacob-ebey/Mirror2
Granted it’s not thought through as long as this project, I have some ideas for how to handle modules that I will be implementing there as a POC before I bring anything here.
I merged you PR. But to add to the discussion: the reason it is javascript in stead of json, is that it allows modules to use callbacks as configuration options. The reason your example breaks is -as others say- because you insert a node.js only statement in a file that is used by both the server as well as the browser. An easy solution would have been something like this: