-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cli): exclude the crypto module #3819
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
修复小程序端使用了 mobx 时不能用循环 ref 的问题。
* feat(taro-cli): 软件包更新列表新增 nervjs 和 nerv-devtools * feat(taro-cli): taro update 更新 nervjs 依赖
…eact-native-swiper@1.5.14
1. git clone 改为使用 download-git-repo 下载 zip 包 2. readdir 去掉 withFileTypes,兼容旧版本 nodejs
This reverts commit 3e4e89c.
即使 taro 不做处理,crypto 这个模块应该也是不能在小程序里使用的,建议换个包吧 |
我们的小程序就是做密码学加密传输数据的功能,而这个bug和crypto模块无关,只是在库的加载判断时,taro无法判断crypto实际不会在浏览器中使用却仍然认为这是一个dependency导致的 tweet-nacl库的加载代码如下: (function() {
// Initialize PRNG if environment provides CSPRNG.
// If not, methods calling randombytes will throw.
var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
if (crypto && crypto.getRandomValues) {
// Browsers.
var QUOTA = 65536;
nacl.setPRNG(function(x, n) {
var i, v = new Uint8Array(n);
for (i = 0; i < n; i += QUOTA) {
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
}
for (i = 0; i < n; i++) x[i] = v[i];
cleanup(v);
});
} else if (typeof require !== 'undefined') {
// Node.js.
crypto = require('crypto');
if (crypto && crypto.randomBytes) {
nacl.setPRNG(function(x, n) {
var i, v = crypto.randomBytes(n);
for (i = 0; i < n; i++) x[i] = v[i];
cleanup(v);
});
}
}
})(); |
试试这个?crypto-js, 我用这个没问题 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
这个 PR 做了什么? (简要描述所做更改)
在微信小程序中开发涉及密码学对称/非对称加解密功能时,
我们使用了一些如 tweetnacl 的库,
在引入时遇到
require('crypto')
会报错,原因是crypto只在node端可用( https://github.com/dchest/tweetnacl-js/blob/3e4e6ac4692a6a445d058bf4f2a60cbaa90d26a1/nacl-fast.js#L2366 )。
但此模块实际上遵循umd引入规则,不应有此错误。
同时,npm中的crypto模块也不能在浏览器使用,
所以taro编译时应该exclude crypto库来避免类似问题。
这个 PR 是什么类型? (至少选择一个)
这个 PR 满足以下需求:
这个 PR 涉及以下平台:
其它需要 Reviewer 或社区知晓的内容:
taro-cli 中的jest存在bug,无法通过