如何在Node 5.6.0环境中运行Node 6 npm软件包?

时间:2022-08-15 22:58:06

I'm currently using a package for running cross browser javascript tests called easy-sauce. In short, my package.json file calls that for the test command:

我目前正在使用一个程序包来运行跨浏览器的javascript测试,称为easy-sauce。简而言之,我的package.json文件调用test命令:

{
  "scripts": {
    "test": "easy-sauce"
  }
}

When I'm using a Node 6 environment, and run npm test, all is well. However, the project I'm using it with still needs Node 5.6.0. When I run npm test in this environment, I see the following error:

当我使用Node 6环境并运行npm test时,一切都很顺利。但是,我正在使用它的项目仍然需要Node 5.6.0。当我在这个环境中运行npm test时,我看到以下错误:

/data/projects/easytest/node_modules/easy-sauce/lib/cli.js:114
function formatResult(result = {}) {
                         ^

SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/data/projects/easytest/node_modules/easy-sauce/bin/easy-sauce:6:13)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)

Is there a way to get this working within the Node 5.6.0 environment?

有没有办法让这个在Node 5.6.0环境中运行?

2 个解决方案

#1


1  

This error isn't related to the easy-sauce package, it has to do with your version of node.

此错误与easy-sauce包无关,它与您的节点版本有关。

According to node.green, default parameters were added in version 6.2.2

根据node.green,版本6.2.2中添加了默认参数

http://node.green/

Unfortunately you wont be able to run the code in node 5. Default parameters are in node 6.2, hence that error.

不幸的是,您无法在节点5中运行代码。默认参数在节点6.2中,因此该错误。

#2


1  

Option 1 Upgrade your version of node/npm. This is not always possible, depending on deployment environment.

选项1升级您的node / npm版本。根据部署环境,这并不总是可行的。

Option 2 You need to use a transpiler (e.g. Babel) to convert the ES6 code to ES5 and reference the built script. This solution is the one you always have the power to do.

选项2您需要使用转换器(例如Babel)将ES6代码转换为ES5并引用构建的脚本。这种解决方案是您始终有能力做到的。

Option 3 Fork/update easy-sauce to include a transpiler to build an ES5 version (in the dist folder is a common destination). The package.json of the package can be directed to this location.

选项3分叉/更新easy-sauce包含一个转换器来构建ES5版本(在dist文件夹中是一个常见的目的地)。包的package.json可以定向到这个位置。

#1


1  

This error isn't related to the easy-sauce package, it has to do with your version of node.

此错误与easy-sauce包无关,它与您的节点版本有关。

According to node.green, default parameters were added in version 6.2.2

根据node.green,版本6.2.2中添加了默认参数

http://node.green/

Unfortunately you wont be able to run the code in node 5. Default parameters are in node 6.2, hence that error.

不幸的是,您无法在节点5中运行代码。默认参数在节点6.2中,因此该错误。

#2


1  

Option 1 Upgrade your version of node/npm. This is not always possible, depending on deployment environment.

选项1升级您的node / npm版本。根据部署环境,这并不总是可行的。

Option 2 You need to use a transpiler (e.g. Babel) to convert the ES6 code to ES5 and reference the built script. This solution is the one you always have the power to do.

选项2您需要使用转换器(例如Babel)将ES6代码转换为ES5并引用构建的脚本。这种解决方案是您始终有能力做到的。

Option 3 Fork/update easy-sauce to include a transpiler to build an ES5 version (in the dist folder is a common destination). The package.json of the package can be directed to this location.

选项3分叉/更新easy-sauce包含一个转换器来构建ES5版本(在dist文件夹中是一个常见的目的地)。包的package.json可以定向到这个位置。