首页 > 解决方案 > 条纹 - 未定义全局

问题描述

当我想使用条带 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中,但仍然没有。

你能帮助我吗 ?

标签: node.jsangulartypescriptstripe-paymentsionic4

解决方案


我记得不久前解决这个问题,我创建了一个 shim 文件并将其导入到 polyfills 中。我不记得为什么,但我似乎记得您不能直接在 polyfills.ts 文件中执行此操作。

垫片文件

(window as any).global = window;

Polyfills.ts

import './global-shim';

推荐阅读