[node v14.x+] Warning: Accessing non-existent property ‘padLevels’ of module exports inside circular dependency in foreversd forever
Explanation of the problem
The execution of the command forever start app.js
results in the following warning:
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: bot.js
(node:14545) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:14545) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
The warning message indicates that the --minUptime
and --spinSleepTime
options are not set, causing Forever to default to a minimum uptime of 1000ms. This means that the script being executed, app.js
, must remain up for at least 1000ms in order to avoid termination.
Additionally, the error message (node:14545) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
is produced twice, indicating a circular dependency issue with a module in the app.js
script. This error may prevent the process from starting correctly, leading to the result shown by the forever list
command:
(node:14574) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:14574) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
info: No forever processes running
The above output from forever list
indicates that no processes are currently running, likely due to the circular dependency error and lack of specified --minUptime
and --spinSleepTime
options. To resolve these issues, the circular dependency error in the app.js
script must be addressed and the --minUptime
and --spinSleepTime
options should be set as desired.
Troubleshooting with the Lightrun Developer Observability Platform
Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.
- Instantly add logs to, set metrics in, and take snapshots of live applications
- Insights delivered straight to your IDE or CLI
- Works where you do: dev, QA, staging, CI/CD, and production
Start for free today
Problem solution for [node v14.x+] Warning: Accessing non-existent property ‘padLevels’ of module exports inside circular dependency in foreversd forever
The warning message (node:14545) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
indicates that there is an issue with a circular dependency in one of the modules being used in the script being executed with Forever.
A circular dependency occurs when two or more modules depend on each other, causing an endless loop that can cause the script to fail. In this case, the error message is indicating that the script is attempting to access a property, 'padLevels'
, that doesn’t exist on the exports
object of a module, while inside a circular dependency.
To resolve this issue, the circular dependency must be identified and broken by refactoring the code. This can be done by rearranging the module dependencies or using a different module structure altogether. The node --trace-warnings ...
option can also be used to show the location where the warning was created, which can provide further insight into the source of the circular dependency.
Other popular problems with foreversd forever
Problem: Missing or incorrect configuration options
One of the most common problems with Forever is missing or incorrect configuration options. For example, when the --spinSleepTime
option is not set, Forever will default to a minimum uptime of 1000ms. This can cause the script to exit if it does not stay up for at least 1000ms, as indicated by the following warning message:
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
Solution:
To resolve this issue, the --spinSleepTime
option should be set to a desired value, such as --spinSleepTime 10000
for a 10 second sleep time. This can ensure that the script remains up for a specified amount of time, even if it encounters temporary issues.
Problem: Circular Dependency Errors
Another common problem with Forever is circular dependency errors, which occur when two or more modules depend on each other. This can cause an endless loop and prevent the script from running correctly. For example:
(node:14545) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:14545) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
Solution:
To resolve circular dependency errors, the code must be refactored to eliminate the circular dependency. This can be done by rearranging the module dependencies or using a different module structure. The node --trace-warnings ...
option can also be used to provide more information about the source of the circular dependency.
Problem: Lack of Resource Management
Finally, another common problem with Forever is the lack of resource management. When a script is running with Forever, it can consume significant system resources and cause other processes to slow down or fail. For example, if a script is using a large amount of memory, it can cause the system to become unresponsive.
Solution:
To resolve this issue, resource usage should be monitored and managed appropriately. This can be done by using resource-management tools, such as ulimit
, to set limits on the amount of memory and other resources that a script can consume. Additionally, the --minUptime
and --spinSleepTime
options can be used to ensure that the script is only running for a specified amount of time, reducing the overall resource usage.
A brief introduction to foreversd forever
Forever is a Node.js utility that allows developers to run scripts continuously and automatically restart them if they fail. It provides a simple and efficient way to keep Node.js applications running in the background, even if the system is restarted or the process is killed. The forever start
command is used to start a script and run it continuously, while the forever stop
command is used to stop it.
Forever is designed to work with Node.js applications that are designed to run continuously in the background. It can be used to run a wide range of applications, including network servers, background jobs, and command-line utilities. The utility provides several options for controlling how scripts are run, including setting a minimum uptime, managing resource usage, and specifying the number of times a script should be restarted if it fails. This makes it an essential tool for managing Node.js applications and ensuring they remain available and responsive to users.
Most popular use cases for foreversd forever
- Continuous Running of Node.js Scripts: Foreversd forever can be used to run Node.js scripts continuously, ensuring that they remain available and responsive to users even if the system is restarted or the process is killed. The
forever start
command can be used to start a script and run it continuously, while theforever stop
command can be used to stop it.
forever start app.js
- Automatic Restart of Failed Scripts: Foreversd forever can automatically restart scripts that fail, ensuring that applications remain available even if there is a problem. The number of times a script should be restarted if it fails can be specified, as well as the time between restarts.
forever start --spinSleepTime 1000 --maxRestarts 3 app.js
- Management of Resource Usage: Foreversd forever provides options for controlling how scripts are run, including setting a minimum uptime, managing resource usage, and specifying the number of times a script should be restarted if it fails. This makes it an essential tool for managing Node.js applications and ensuring they remain available and responsive to users.
forever start --minUptime 1000 --spinSleepTime 1000 app.js
It’s Really not that Complicated.
You can actually understand what’s going on inside your live applications.