nodejs 运行代码报错

 function n(t) {
        return JSON.parse(a("5e5062e82f15fe4ca9d24bc561080e0e",atob(t),0,0,"012345677890123",1))

/home/shenjianlin/js/code.js:48
return JSON.parse(a("5e5062e82f15fe4ca9d24bc561080e0e",atob(t),0,0,"012345677890123",1))

sudo npm install btoa-atob
bin@1.0.0 /usr/bin
└── btoa-atob@0.1.2

                                                   ^

我已经安装了 atob 这个包了还是说我没有

ReferenceError: atob is not defined

at n (/home/shenjianlin/js/code.js:48:56)
at Object.<anonymous> (/home/shenjianlin/js/code.js:55:13)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.runMain (module.js:611:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:160:9)

阅读 4.7k
1 个回答

btoa-atob 只是命令行工具,你应该安装的包是 atob, 并在代码中显示引入:

const atob = require('atob');
function n(t) {
    return JSON.parse(a("5e5062e82f15fe4ca9d24bc561080e0e",atob(t),0,0,"012345677890123",1))
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏