camelcase 包出现错误。类型错误:input.replaceAll 不是函数

问题描述 投票:0回答:1

使用camelcase npm 包时出现此错误。

>file:///Users/.../using-package-camelcase/node_modules/camelcase/index.js:54
        .replaceAll(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier));   
            ^  
>TypeError: input.replaceAll is not a function 

重新安装软件包。

javascript replace typeerror replaceall camelcasing
1个回答
0
投票

我尝试修改node_module>camlecase>index.js中的包,它工作正常。 错误出现在这一行:

    return input
        .replaceAll(NUMBERS_AND_IDENTIFIER, (match, pattern, offset) => ['_', '-'].includes(input.charAt(offset + match.length)) ? match : toUpperCase(match))
        .replaceAll(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier));

TypeError:input.replaceAll 不是函数

所以我改变了:

replaceALL() 替换()

    return input
        .replace(NUMBERS_AND_IDENTIFIER, (match, pattern, offset) => ['_', '-'].includes(input.charAt(offset + match.length)) ? match : toUpperCase(match))
        .replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier));

这有帮助,程序运行并且错误消失了。

© www.soinside.com 2019 - 2024. All rights reserved.