angular - 使用 Apache thrift 在 Nativescript + Angular 中“无法读取未定义的属性 'browser'”

标签 angular webpack nativescript babeljs thrift

我正在尝试将 Apache Thrift 与我的 Angular 和 Nativescript 项目一起使用,但是通过“tns preview --bundle”或我得到的任何其他 tns 命令

TypeError: Cannot read property 'browser' of undefined
File: "<unknown>, line: 1, column: 265

Apache Thrift v. 0.11.0/1.0.0dev,Angular v. 7.1.0,Nativescript v. 5.1.0

在 platforms/android/app/src/main/assets/app/vendor.js 我可以看到:

/* istanbul ignore next */
if (undefined.browser) {
    defaultEncoding = 'utf-8'
} else {
    var pVersionMajor = parseInt(undefined.version.split('.')[0].slice(1), 10)

当我期待像 global.process.browser 这样的东西时,我却可以在 vendor.js 的另一个地方找到它。 在另一个和平中,我可以看到类似 undefined.nextTick(...) 等的东西。 我知道这是某种 Babel 问题,但我不知道如何解决它。

我使用 thrift --gen js:node 脚本来生成我的 thrift 文件(它在错误中没有意义)。没有它们,一切都很好,但后来我试图从节俭中执行任何节俭生成的文件/任何模块,我在上面得到了一个异常(exception)。 我的组件.ts

import { Component, OnInit } from '@angular/core';
import { TJSONProtocol } from 'thrift'; // or anything else 

@Component({...});

export class MyComponent implements OnInit {
    ngOnInit () {
        // console.log(TJSONProtocol); // Uncomment this string to get an exception.
    }
    constructor() {...};
}

ng serve 提供的任何问题。 我希望这里有任何方法可以解决此错误并使 thrift 与 nativescript 兼容,或者以任何其他方式将 thrift 与 nativescript 一起使用。

最佳答案

问题出在 Nativescript 提供的默认 webpack.config.js 中。在:

plugins: [
        // Define useful constants like TNS_WEBPACK
        new webpack.DefinePlugin({
            "global.TNS_WEBPACK": "true",
            "process": undefined,
        })

您需要删除行 "process": undefined

关于angular - 使用 Apache thrift 在 Nativescript + Angular 中“无法读取未定义的属性 'browser'”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53945922/

相关文章:

Angular 应用程序无法使用 GitHub 操作 ('Cannot find module' 构建)

angular - 带有 ngFor 元素的 ngModel 的动态 angular2 形式

javascript - 具有两个公共(public) block 的 Webpack : one exported, 一个本地

webpack - 无法使用 Electron 生成器找到依赖关系(node-pre-gyp)

android - 如何在 NativeScript 中访问 Google Play 服务

ios - 在 NativeScript 中访问 iOS 通用链接中的查询参数

javascript - Angular 2 - 子路由与父组件有不同的父组件

angular - agm 标记不从 ngfor 渲染

express - Webpack 和 Express - 严重依赖警告

javascript - SQLite Nativescript中按列名读取查询结果