【发布时间】:2023-03-13 17:28:06
【问题描述】:
当我尝试在 clojurescript 项目中要求 Sha256 时:
(ns tutorial-client.sha256
(:require
[goog.crypt.Sha256 :as hasher]))
我没有收到实际的编译错误,但是当我在浏览器中打开 clojurescript->js 输出时确实收到以下内容。
Uncaught Error: Undefined nameToPath for goog.crypt.Sha256 base.js:586
Uncaught ReferenceError: cljs is not defined rendering.js:7
goog.require could not find: goog.crypt.Sha256 base.js:333
Uncaught Error: goog.require could not find: goog.crypt.Sha256 base.js:337
Uncaught ReferenceError: cljs is not defined behavior.js:8
Uncaught ReferenceError: cljs is not defined app.js:100
Uncaught TypeError: Cannot read property 'IE' of undefined eventtype.js:60
Uncaught TypeError: Cannot read property 'entryPointRegistry' of undefined events.js:1084
Uncaught TypeError: Cannot read property 'IE' of undefined browserfeature.js:35
Uncaught TypeError: Cannot read property 'Error' of undefined asserts.js:71
Uncaught TypeError: Cannot read property 'prototype' of undefined base.js:1407
Uncaught Error: Invalid event type events.js:139
Uncaught Error: Invalid event type events.js:139
Uncaught TypeError: Cannot call method 'call' of undefined
我认为其中大部分可能可以忽略,问题是它基本上找不到 goog.crypt.Sha256 的顶级错误。有趣的是,如果我将代码更改为以下内容,我可以消除所有错误。
(ns tutorial-client.sha256
(:require
[goog.net.XhrIo :as hasher]))
无论如何,我只想访问 goog.crypt.sha256 。谢谢。
【问题讨论】:
-
调用 clojurescript 时在浏览器中加载 js 就足够了。如果你做高级编译,别忘了设置externs。
-
啊,我看到你是在基座上做的。有趣的是,我也做了一个加密应用程序作为第一个项目。是的,在基座中 goog.require 不是必需的。确保您在 application.html 和(如果您在数据流方面需要它)tooling.html 中有 js。
-
谢谢我试了一下,但我似乎遇到了麻烦,可能真的很简单,但这就是这些配置的方式。我在基座用户组上发布了我的问题的 git 示例。如果我得到一个答案,我会写一个答案。
-
如果有人想直接修复基座代码,链接在这里。 groups.google.com/forum/#!topic/pedestal-users/9iy6YsIWDEo
-
我应该已经添加了,您可以通过 cd'ing 进入目录运行上述代码,输入“lein repl”,然后输入“(start)”启动服务器。然后在 3000 端口访问应用程序。
标签: clojure closures google-closure-compiler google-closure clojurescript