nodejs 运行代码报错

stephen2017
  • 0
新手上路,请多包涵
 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)

回复
阅读 2.1k
1 个回答

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

const atob = require('atob');
function n(t) {
    return JSON.parse(a("5e5062e82f15fe4ca9d24bc561080e0e",atob(t),0,0,"012345677890123",1))
}
你知道吗?

宣传栏