node.js - 收到错误 args.includes is not a function Node js

标签 node.js npm

我有 Node -v v4.4.4

和 npm -v 5.1.0

我得到了错误:- args.includes 不是 Node js 的函数。这可能不是 npm 的问题。

请提供同样的帮助。

示例代码如下:-

const fs = require('fs');
const path = require('path');
const REST_API_PROD = '.';
const REST_API_DEV = '/ms-si-api';
var args = process.argv.slice(2);

const readFile = path.resolve(__dirname, '../src/api-host.template');
fs.readFile(readFile, 'utf8', (err, data) => {
if (err) {
    return console.log(err);
}
const isProd = args.includes('--prod');
console.log(isProd)
var result = data.replace(/{%host%}/g, isProd ? REST_API_PROD : REST_API_DEV);
const writeFile = path.resolve(__dirname, '../src/api-host.ts');
fs.writeFile(writeFile, result, 'utf8', (err) => {
    if (err) {
        return console.log(err);
    }
});

});

最佳答案

错误消息说明了一切。您的 Node.js 版本根本不支持 Array.prototype.includes。您需要将 Node.js 升级到至少 6.0 版本才能获取它。

参见http://node.green/#ES2016-features-Array-prototype-includes

关于node.js - 收到错误 args.includes is not a function Node js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48908639/

相关文章:

node.js - Grunt安装失败

node.js - npm global 没有被使用?

node.js - npm 安装失败,出现 'subset is not a function'

node.js - NodeJS readline 自动完成几个单词

Node.js Nodemailer 和 SES - 错误 : No transport method defined

node.js - 在 Bot Framework 中检测表情符号

node.js - 安装 npm 时出现 403 禁止 - Ubuntu 14.0

javascript - NodeJS Multer在上传之前验证字段

node.js - 当我使用 Ghost-cli 安装 Ghost 时出现错误

git - "node_modules"文件夹是否应该包含在 git 存储库中