javascript - 条纹。TypeError:document.querySelectorAll 不是函数
问题描述
我正在使用 Meteor 框架和 React。
添加了@stripe 包。付款表格有效,但它不断在日志中显示以下内容:
UnhandledPromiseRejectionWarning: TypeError: document.querySelectorAll is not a function
at findScript (/project/node_modules/@stripe/stripe-js/dist/stripe.js:9:26)
at /project/node_modules/@stripe/stripe-js/dist/stripe.js:75:20
at new Promise (<anonymous>)
at loadScript (/project/node_modules/@stripe/stripe-js/dist/stripe.js:57:19)
at /project/node_modules/@stripe/stripe-js/dist/stripe.js:113:10
at /.meteor/packages/promise/.0.11.2.1e1wn8z.joczg++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40
我怎么解决这个问题?
解决方案
这似乎是您在服务器上看到的错误(否则node_modules
不会显示路径)。因此,您似乎正在尝试在服务器端呈现条带表单。这不起作用,因为,是的,该功能在服务器上不存在。我认为你最好的选择是在使用这种条带形式的反应组件中添加一个保护。像这样的东西:
const MyPaymentForm = (props) => {
if (Meteor.isServer) {
return <div>Stripe form will load dynamically on client</div>;
}
render <div suppressHydrationWarning={true}>
<StripeProviver>...</StripeProvider>
</div>;
};
客户端版本上的suppressHydrationWarning
参数是为了避免(常见的)React 错误,即在客户端上与从服务器返回的形状不同的 HTML 水合。
推荐阅读
- material-ui - DatePicker (material-ui-picker) onChange 无法将值传递给 redux-form onChange 事件
- android - Oreo:当我使用 NotificationManager.IMPORTANCE_LOW 时,通知不会出现在状态栏中
- excel - 如何添加来自不同工作表的值,并保留指向工作表+单元格的公式?
- text - 减小松弛消息中文本的大小
- ios - 交互式视图控制器转换 - 奇怪的行为(卡在转换中)
- oracle - 删除具有全局索引的分区表?
- angular - 构建突然开始失败并出现错误 TS2304:找不到名称“JQueryDeferred”
- c - 在 C 中检查 opencl 版本
- google-bigquery - 我如何知道 BigQuery 响应的大小
- android - 我们如何在每毫秒内缓冲项目并以恒定的时间间隔流式传输每个项目