-
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
taro3.x 引入 lodash 错误 #8098
Comments
目前通过在 app.js(app.tsx) 中 写入
处理 |
我调试得知访问 Array.prototype 时报错,此 Array 来自于 root.Array,root 又来自于
这个就无解了,要么篡改这个 lodash 的 root 的赋值
要么就只能如你代码所说按需引入,不能全局引入。 |
Taro 3.6.6 依然可以复现,大佬们来修下呀 |
Taro 3.6.6 里对于 |
尝试在小程序入口文件引入lodash-fix.js |
试试这样? |
这是来自QQ邮箱的假期自动回复邮件。
您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
|
大兄弟这个可以 |
Taro3 版本下使用 lodash 或者 lodash-es 都会报错。
root 在运行时发现是 undefined。
这样不会有问题 |
微信小程序下也遇到了,taro@3.6.32,lodash-es@4.17.21 |
这是来自QQ邮箱的假期自动回复邮件。
您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
|
基础库版本问题项目中使用了
在 在
微信小程序中使用 lodash 不会报错关闭 sourceMap 后可以方便从控制台直接进入实际代码。 export default {
mini: {
enableSourceMap: false,
},
} satisfies UserConfigExport; 打开 vendors.js 可以看到 node_modules/lodash/lodash.js 中的
// 编译前
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
// 编译后
var freeGlobal = typeof __webpack_require__.g == 'object' && __webpack_require__.g && __webpack_require__.g.Object === Object && __webpack_require__.g; 微信小程序中存在
var runInContext = (function runInContext(context) {
context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
/** Built-in constructor references. */
var Array = context.Array,
Date = context.Date,
Error = context.Error,
Function = context.Function,
Math = context.Math,
Object = context.Object,
RegExp = context.RegExp,
String = context.String,
TypeError = context.TypeError;
/** Used for built-in method references. */
var arrayProto = Array.prototype,
funcProto = Function.prototype,
objectProto = Object.prototype;
// ...
});
好奇研究了一下 normalModuleFactory.hooks.parser
.for(JAVASCRIPT_MODULE_TYPE_ESM)
.tap(PLUGIN_NAME, handler); 说明 NodeStuffPlugin 不解析 ESM 包 ( 参考 webpack/webpack#14210 (comment) ),而 解决办法
上面这些方法目的都是为了让
记得比较修改前后的 vendors.js 内容,查看具体替换了哪些代码。 lodash 简易版按需引入export default {
alias: {
lodash: 'lodash-es',
},
} satisfies UserConfigExport; 相关问题
最后以上分析主要针对 微信小程序 ,其他小程序环境没试过,但思路应该一样的。 虽然没做过支付宝小程序不太了解,但看 文档 目前应该已经支持
|
这是来自QQ邮箱的假期自动回复邮件。
您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
|
相关平台
支付宝小程序
小程序基础库: 无
使用框架: React
复现步骤
期望结果
期望无报错
实际结果
h5与微信小程序无报错,支付宝小程序报错为:
import { debounce } from 'lodash' 此方法引入,页面加载失败,报错为 TypeError: Cannot read property 'prototype' of undefined
or
import { debounce } from 'lodash/function' 此方法引入,页面正常加载,当触发onChange 事件时,报错为 TypeError: Cannot read property 'now' of undefined
环境信息
The text was updated successfully, but these errors were encountered: