garris / BackstopJS

Catch CSS curve balls.
http://backstopjs.org
MIT License
6.66k stars 602 forks source link

backstop remote doesnt work with nvm? #1509

Closed cimak closed 7 months ago

cimak commented 7 months ago

I have two versions of node installed:

> nvm use 21
Now using node v21.2.0 (npm v10.2.3)

> node --version
v21.2.0

Problem

If I now run backstop remote, it will execute super-simple-web-server script with node v10.19.0 :

> backstop remote --config="backstop.config.cjs"
BackstopJS v6.2.2
Loading config:  /mnt/c/projects/[...]/backstop.config.cjs
COMMAND | Executing core for "remote"
 remote | Starting remote with: node /mnt/c/projects/[...]/node_modules/super-simple-web-server/index.js [...]
                                  ^ this runs v10.19.0 from /usr/bin

and that's a problem because v10 does not support optional chaining, so I'm getting Unexpected token . errors in runPuppet.js.

Cause

Looking at backstopjs\core\command\remote.js, I think the problem is caused by calling exec with narrowed env:

const commandStr = `node ${ssws} ${projectPath} ${MIDDLEWARE_PATH} --config=${config.backstopConfigFileName}`;
const env = {'SSWS_HTTP_PORT': port }; // no PATH passed?
[...]
const child = exec(commandStr, {env: env});

Solution?

changing:

const env = {'SSWS_HTTP_PORT': port };

to:

const env = {'SSWS_HTTP_PORT': port, ...process.env};

seems to be solving the problem.

cimak commented 7 months ago

Duplicate of #1488