Skip to content

Conversation

webdiscus
Copy link
Contributor

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR https://github.com/pm2-hive/pm2-hive.github.io/pulls

Hello,

I'm the author of Ansis, a smaller and faster alternative to Chalk.
Ansis is a dual package that supports both CommonJS and ESM, while Chalk v5 is ESM only.

Ansis is Chalk-compatible, so migrating requires minimal code changes.
For example:

- const chalk = require('chalk');
+ const chalk = require('ansis');

...

- chalk.bold.grey('text'); // uncommon UK spelling
+ chalk.bold.gray('text'); // Ansis uses the common standard spelling

This PR intentionally keeps the variable name chalk unchanged (i.e., chalk.red() instead of ansis.red()) to demonstrate that only minimal changes are needed, typically just the import and occasional spelling updates like grey -> gray.

If you'd prefer a full rename to, e.g., ansis.red(), I'm happy to update the variable name throughout the codebase as well.

@CLAassistant
Copy link

CLAassistant commented May 11, 2025

CLA assistant check
All committers have signed the CLA.

@webdiscus webdiscus marked this pull request as ready for review May 11, 2025 17:02
@Unitech
Copy link
Owner

Unitech commented May 12, 2025

Great!

@Unitech Unitech merged commit 064a4a8 into Unitech:development May 13, 2025
3 checks passed
@cristianst
Copy link

cristianst commented May 13, 2025

Hi @webdiscus , quick heads up: we just encounter one issue in our deployment process after the last pm2 release. It seems like ansis is not being installed correctly as dependency?

image

Rolling back to: npm install -g [email protected] solves the issue. Could you verify? Happy to contribute further here.

@webdiscus
Copy link
Contributor Author

Hello @cristianst,

probably the issue is in the "old" package-lock.json.
I will check it.

jeremyschlatter added a commit to jeremyschlatter/pm2 that referenced this pull request May 13, 2025
Fixes Unitech#5984
Fixes Unitech#5983 (comment)

Also adds integrity hashes.

Created by running the following command:

    rm bun.lock package-lock.json && npm install --package-lock-only && bun install --lockfile-only
@webdiscus
Copy link
Contributor Author

@cristianst, I can't reproduce the issue with v6.0.6.

image

Here is the repo test-pm2-deploy-docker to test pm2 deploy into a docker container.

Note

The exact same PM2 version (6.0.6) is installed both locally and in the Docker container.

Info

  • macOS: 15.5
  • node -v -> v22.15.0
  • pm2 -v -> 6.0.6

Which version of Node.js is currently installed?
PM2 6.0.6 requires Node.js 16 or late, package.json:

"engines": {
    "node": ">=16.0.0"
 },

Do you use NVM to manage Node.js versions?
PM2 must be installed globally for each Node.js version used with NVM.

@cristianst
Copy link

Thanks for verifying, @webdiscus. I'm afraid we're still using an older version of Node (10.x). I know, it's pretty outdated… we're already working on it.

That said, despite the old Node version, [email protected] (installed globally) was working fine for us until [email protected] was released. Your initial guess seems to be spot on: I noticed that the package-lock.json is missing.

In fact, there's already a PR addressing this: #5985. Pretty sure this might solve the issue.

@webdiscus
Copy link
Contributor Author

@cristianst, @jeremyschlatter, @Unitech

Breakdown of the error Error: Cannot find module 'ansis'

This indicates that Ansis is either not installed properly or cannot be loaded in Node.js v10 due to compatibility issues.

Since PM2 v6 officially requires Node.js >= 16, the latest version 6.0.6 migrated from outdated chalk v3 to ansis.
Ansis requires Node.js >= 14 (which is still lower than PM2's own minimum requirement).
However, PM2 v6 can still run unofficially on Node.js >= 10, which leads to this error for users running Node.js v10 - v12, because Ansis does not support such old versions.

To address this, I've created a special version of Ansis: 4.0.0-node10, which is compatible with Node.js 10+.

TODO: fix PM2 dependency:

"dependencies": {
 ..
- "ansis": "4.0.0",
+ "ansis": "4.0.0-node10",
 ..
}

@jeremyschlatter
Copy link

I was skeptical that this was the cause, but indeed it is. A simple way to verify is to compare the output of these commands:

docker run --rm -it --entrypoint bash node:10 -c 'npm install -g pm2; pm2'
docker run --rm -it --entrypoint bash node:16 -c 'npm install -g pm2; pm2'

$ docker run --rm -it --entrypoint bash node:10 -c 'npm install -g pm2; pm2 --version'
/usr/local/bin/pm2-runtime -> /usr/local/lib/node_modules/pm2/bin/pm2-runtime
/usr/local/bin/pm2-dev -> /usr/local/lib/node_modules/pm2/bin/pm2-dev
/usr/local/bin/pm2 -> /usr/local/lib/node_modules/pm2/bin/pm2
/usr/local/bin/pm2-docker -> /usr/local/lib/node_modules/pm2/bin/pm2-docker
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">=16.0.0"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">=14"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 14"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 14"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 14"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 14"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 14"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 14"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">=12"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 14"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 14"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 14"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 14"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 12"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/pm2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm64"})

+ [email protected]
added 135 packages from 169 contributors in 5.639s
internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'ansis'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/pm2/constants.js:10:14)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
$ docker run --rm -it --entrypoint bash node:16 -c 'npm install -g pm2; pm2'

added 135 packages, and audited 136 packages in 2s

13 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm notice
npm notice New major version of npm available! 8.19.4 -> 11.3.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.3.0
npm notice Run npm install -g [email protected] to update!
npm notice

                        -------------

__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
 _\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
  _\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
   _\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
    _\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
     _\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
      _\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
       _\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
        _\///______________\///______________\///__\///////////////__


                          Runtime Edition

        PM2 is a Production Process Manager for Node.js applications
                     with a built-in Load Balancer.

                Start and Daemonize any application:
                $ pm2 start app.js

                Load Balance 4 instances of api.js:
                $ pm2 start api.js -i 4

                Monitor in production:
                $ pm2 monitor

                Make pm2 auto-boot at server restart:
                $ pm2 startup

                To go further checkout:
                http://pm2.io/


                        -------------

usage: pm2 [options] <command>

pm2 -h, --help             all available commands and options
pm2 examples               display pm2 usage examples
pm2 <command> -h           help on a specific command

Access pm2 files in ~/.pm2

You can see among the warnings in the first command:

npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">=14"} (current: {"node":"10.24.1","npm":"6.14.12"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]

Presumably this is the cause of the regression, as [email protected] only node >=8:

	"engines": {
		"node": ">=8"
	},

Though you can also see in the warnings that a bunch of other stuff is listed as unsupported on Node 10, too. Namely proxy-agent, https-proxy-agent, pac-proxy-agent, lru-cache, socks-proxy-agent, agent-base, http-proxy-agent, get-uri, pac-resolver, data-uri-to-buffer, degenerator, and ip-address.

@see365
Copy link

see365 commented May 15, 2025

The minor version upgrade from 6.0.5 to 6.0.6 should not require a Node.js version change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants