Angular 6-尝试为应用程序提供服务时未定义过程 [英] Angular 6 - process is not defined when trying to serve application

查看:80
本文介绍了Angular 6-尝试为应用程序提供服务时未定义过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用cosmicjs服务我的angular 6应用程序时,出现以下错误:

I am getting the following error when I try to serve my angular 6 application using cosmicjs:

Uncaught ReferenceError: process is not defined
    at Object../node_modules/cosmicjs/dist/index.js (index.js:6)
    at __webpack_require__ (bootstrap:81)
    at Object../src/app/app.component.ts (main.js:94)
    at __webpack_require__ (bootstrap:81)
    at Object../src/app/app.module.ts (app.component.ts:9)
    at __webpack_require__ (bootstrap:81)
    at Object../src/main.ts (environment.ts:18)
    at __webpack_require__ (bootstrap:81)
    at Object.0 (main.ts:12)
    at __webpack_require__ (bootstrap:81)

我最新的理论与process.env属性未定义有关.

My latest theory is something to do with the process.env property being undefined.

我正在此处此处

I'm following this tutorial here

此处

本教程似乎使用的是angular的旧版本,而不是新的angular.json,而使用的是.angular-cli.json,我认为这是尝试指定环境变量的问题的一部分.

The tutorial seems to be using an older version of angular that uses .angular-cli.json instead of the new angular.json and I think this is part of the issue in trying to specify the environment variables.

推荐答案

polyfill.ts中,添加以下行:

(window as any).process = {
  env: { DEBUG: undefined },
};

参考: https://github.com/algolia/algoliasearch-client- javascript/issues/691

npm i -S process,然后将其添加到polyfill.ts:

import * as process from 'process';
window['process'] = process;

这篇关于Angular 6-尝试为应用程序提供服务时未定义过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆