Angular 6 - 尝试为应用程序提供服务时未定义进程 [英] Angular 6 - process is not defined when trying to serve application
问题描述
当我尝试使用 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.
我正在学习本教程此处
我的确切代码可以在这里
本教程似乎使用了旧版本的 angular,它使用 .angular-cli.json 而不是新的 angular.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
中,添加这一行:
In polyfill.ts
, add this line:
(window as any).process = {
env: { DEBUG: undefined },
};
参考:https://github.com/algolia/algoliasearch-client-javascript/问题/691
或者npm i -S process
,然后把这个添加到polyfill.ts
:
Or npm i -S process
, then add this to polyfill.ts
:
import * as process from 'process';
window['process'] = process;
这篇关于Angular 6 - 尝试为应用程序提供服务时未定义进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!