我尝试使用标准ng build --prod命令构建一个Angular 5应用程序,并且我想将基本API-Url设置为environment.prod.ts依赖于我的process.env变量的值.
这是我的档案:
export const environment = {
production: true,
apiUrl: `${process.env.BASE_URL}` || 'http://localhost:8070/',
};
Run Code Online (Sandbox Code Playgroud)
但是当我尝试构建应用程序时,会发生以下错误:
ERROR in src/environments/environment.ts(7,16): error TS2304: Cannot find name 'process'.
在构建应用程序时,如何根据env变量设置API-Url?
我使用的是 Angular 15 和 Node 版本 18.12.1。
我在 Visual Studio Code 中创建了一个新应用程序,但了解到 Angular 不再提供用于测试和生产目的的环境文件。
我想要回这些环境文件,因此我按照 Angular 网站的说明进行操作。
https://angular.io/guide/build
我在 PowerShell 中输入“nggenerateenvironments”,但收到以下错误消息:
“错误:执行期间需要集合和原理图”
我需要帮助弄清楚如何让它发挥作用。
我按照 Angular 网站上的说明进行操作,但没有成功。
我还尝试更新我的 Node 版本,以确保它是最新的。
这些都没有解决我创建环境文件的问题。
我遵循了几个教程,他们都在某个时候说“现在去src/environments”。但该文件夹在我的项目中不存在!我尝试删除整个项目并重新创建它,但没有帮助。
我就是这样做的。打开cmd然后:
1. cd my_path
2. npm install -g @angular/cli
3. ng new webversion
--> Angular routing? Yes
--> Stylesheet: CSS
4. cd webversion
5. npm install bootstrap
6. npm install firebase @angular/fire
Run Code Online (Sandbox Code Playgroud)
现在教程开始使用src/environments. 但我就是没有那个文件夹。这是我的angular.json:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"webversion": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/webversion",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": [
"zone.js"
], …Run Code Online (Sandbox Code Playgroud)