node.js - 条纹 - 未定义全局
问题描述
当我想使用条带 API 时遇到问题。
环境:
"devDependencies": {
"@angular-devkit/build-angular": "~0.803.20",
"@angular/cli": "~8.3.23",
"@angular/compiler": "~8.2.14",
"@angular/compiler-cli": "~8.2.14",
"@angular/language-service": "~8.2.14",
"@ionic/angular-toolkit": "^2.1.1",
"@types/node": "^8.9.5",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.4.3"
},
"dependencies": {
"@angular/common": "~8.2.14",
"@angular/core": "~8.2.14",
"@angular/forms": "~8.2.14",
"@angular/platform-browser": "~8.2.14",
"@angular/platform-browser-dynamic": "~8.2.14",
"@angular/router": "~8.2.14",
"@ionic-native/core": "^5.0.0",
"@ionic/angular": "^5.0.0",
"core-js": "^2.5.4",
"rxjs": "~6.5.1",
"stripe": "^8.32.0",
},
节点版本:13.7.0
我的问题
能力.js:1未捕获的ReferenceError:未定义全局
从我使用的那一刻起:
import Stripe from 'stripe';
const stripe = new Stripe('sk_test_...', {
apiVersion: '2020-03-02',
});
我试过(在我的 index.html 或 Polyfills 中):
(window as any).global = window;
global.Buffer = global.Buffer || require('buffer').Buffer;
(window as any).process = {
version: ''
};
类似的事情很多,但总是出错。
我还将Stripe.js放在了我的index.html中,但仍然没有。
你能帮助我吗 ?
解决方案
我记得不久前解决这个问题,我创建了一个 shim 文件并将其导入到 polyfills 中。我不记得为什么,但我似乎记得您不能直接在 polyfills.ts 文件中执行此操作。
垫片文件
(window as any).global = window;
Polyfills.ts
import './global-shim';
推荐阅读
- ms-media-foundation - 如何在 mediafoundation source Reader 和 sink writer 中支持 mxf 文件格式
- python - 如何访问表中的某些数据?
- python - 使用 python 将 XML 转换为 Json 并触发 post API 请求
- php - 无法传递数组数据
- android - 如何使用大单行文本将 ButtonView 定位到 TextView 的末尾,而不是将其移出屏幕
- android - Android Activity 不会停止服务和位置更新
- corespotlight - 在 Spotlight 中重复显示 NSUserActivity
- postgresql - PostgreSQL UPDATE JOIN ...它是如何工作的?
- linux - ncat web server如何获取请求参数和客户端ip
- java - 具有来自连接实体的属性的 Micronaut 数据 DTO 投影