admin管理员组文章数量:1397110
I upgraded to Angular 17 and now ng serve does not run in dev mode, no source map is available. I tried every possible solution I found online related to proxy config, package.json, angular.json. I finally made it at least run and load icons and fonts, but no source map, the console log prints true which means still in production mode despite all the config settings (console.info(environment.production);). Below my project files (confidential info is replaced)
Angular 17.3.12 Node.js 18.20.7
I tried different options and their combinations in all those files, a couple of different node.js versions. I tried using routing function in proxy config but that did not help either. By now, I think I included all possible options that are out there.
With current config settings, at least the page is rendered correctly, all icons, fonts are loaded. PDF file (EULA) is loaded. But it all seems are fetched from the remote server, not my local/dev environment. The dev tools do not show any local source files, no source code changes are reflected on a reload, even though it recognizes that changes did happen.
I spent almost two weeks trying to make it work. Any constructive solution would be truly appreciated. Thank you in advance!!!
PROXY.CONF.JS (I tried same in json format too, no difference)
var proxy_target = process.env.PROXY_TARGET || "1.2.3.4";
var PROXY_CONFIG = [
{
context: [
"/api",
"/rest"
],
target: "https://" + proxy_target + ":443",
secure: false,
optimization: false,
changeOrigin: true,
logLevel: "debug",
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization"
}
},
{
context: [
"/stompEndpoint"
],
target: "https://" + proxy_target + ":443",
secure: false,
optimization: false,
changeOrigin: true,
logLevel: "debug",
ws: true,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization"
}
},
{
context: ['/'],
target: "https://" + proxy_target + ":443",
secure: false,
optimization: false,
changeOrigin: true,
logLevel: "debug",
pathRewrite: {
"^/@fs/my/project/path/src/": "/",
"^/@fs/my/project/path/node_modules/pdfjs-dist/build/": "/assets/js/"
},
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization"
}
}
];
module.exports = PROXY_CONFIG;
--------------------------------------------------------
package.json
{
"name": "my-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.js --configuration=development --ssl true --open",
"serve": "ng serve",
"build": "ng build",
"watch": "ng build --watch",
"prod": "ng build --configuration production",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"pretty": "ng build --configuration production --optimization=false"
},
"private": true,
"dependencies": {
"@angular/animations": "17.3.12",
"@angular/cdk": "17.3.10",
"@angular/common": "17.3.12",
"@angular/compiler": "17.3.12",
"@angular/core": "17.3.12",
"@angular/flex-layout": "15.0.0-beta.42",
"@angular/forms": "17.3.12",
"@angular/material": "17.3.10",
"@angular/platform-browser": "17.3.12",
"@angular/platform-browser-dynamic": "17.3.12",
"@angular/router": "17.3.12",
"@ng-select/ng-select": "12.0.7",
"@xterm/xterm": "5.5.0",
"ajv": "8.8.2",
"async": "3.2.4",
"bufferutil": "4.0.6",
"d3": "7.8.2",
"date-fns": "2.16.1",
"eventsource": "2.0.2",
"jsplumbtoolkit": "file:./src/app/lib/jsplumbtoolkit.tgz",
"jsplumbtoolkit-drop": "file:./src/app/lib/jsplumbtoolkit-drop.tgz",
"jsplumbtoolkit-editable-connectors": "file:./src/app/lib/jsplumbtoolkit-editable-connectors.tgz",
"jsplumbtoolkit-labels": "file:./src/app/lib/jsplumbtoolkit-labels.tgz",
"jsplumbtoolkit-search": "file:./src/app/lib/jsplumbtoolkit-search.tgz",
"jsplumbtoolkit-undo-redo": "file:./src/app/lib/jsplumbtoolkit-undo-redo.tgz",
"lodash": "4.17.21",
"lodash-es": "4.17.21",
"ng-terminal": "6.4.0",
"ng2-pdf-viewer": "10.3.1",
"ngx-cookie-service": "17.1.0",
"ngx-webstorage-service": "4.1.0",
"node": "^20.9.0",
"npm-force-resolutions": "^0.0.10",
"pdfjs-dist": "4.6.82",
"rxjs": "6.5.5",
"sass": "1.43.5",
"tslib": "1.10.0",
"utf-8-validate": "5.0.9",
"xregexp": "5.1.1",
"zone.js": "0.14.10"
},
"devDependencies": {
"@angular-devkit/build-angular": "17.3.12",
"@angular/cli": "17.3.12",
"@angular/compiler-cli": "17.3.12",
"@eslint/config-array": "0.19.2",
"@eslint/object-schema": "2.1.6",
"@rollup/rollup-win32-x64-msvc": "4.35.0",
"@stomp/rx-stomp": "^1.1.4",
"@types/d3": "7.4.0",
"@types/jasmine": "4.0.3",
"@types/jasminewd2": "2.0.10",
"@types/lodash": "4.14.182",
"@types/node": "13.13.52",
"@xterm/addon-fit": "0.10.0",
"engine.io": "6.6.2",
"esbuild": "0.25.0",
"eslint": "9.21.0",
"jasmine-core": "4.3.0",
"jasmine-spec-reporter": "7.0.0",
"json5": "2.2.3",
"karma": "6.4.0",
"karma-chrome-launcher": "3.1.1",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-jasmine": "5.1.0",
"karma-jasmine-html-reporter": "2.0.0",
"loader-utils": "2.0.4",
"net": "1.0.2",
"sockjs-client": "1.6.1",
"ts-node": "10.9.1",
"typescript": "5.4.5",
"ua-parser-js": "0.7.34"
}
}
-------------------------------------------------------------------------
angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"my-app": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser-esbuild",
"options": {
"baseHref": "/",
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
{
"glob": "favicon.ico",
"input": "src",
"output": "/"
},
{
"glob": "pdf.worker.mjs",
"input": "node_modules/pdfjs-dist/build/",
"output": "/assets/js/"
},
{
"glob": "**/*",
"input": "src/assets",
"output": "/assets",
"ignore": ["**/media/**/*"]
}
],
"styles": [
"node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles/styles.scss"
],
"scripts": [],
"allowedCommonJsDependencies": [
"rxjs",
"angular2-uuid",
"xterm",
"pdfjs-dist/build/pdf",
"pdfjs-dist/web/pdf_viewer",
"lodash",
"jsplumbtoolkit-drop",
"jsplumbtoolkit",
"xterm-addon-fit",
"sockjs-client",
"xregexp"
],
"optimization": true
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "50mb",
"maximumError": "50mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
},
"development": {
"optimization": false,
"sourceMap": {
"scripts": true,
"styles": true,
"hidden": true,
"vendor": true
},
"namedChunks": true,
"extractLicenses": false,
"buildOptimizer": false,
"budgets": [
{
"type": "initial",
"maximumWarning": "30mb",
"maximumError": "50mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "20kb",
"maximumError": "40kb"
}
]
}
},
"defaultConfiguration": "development"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"buildTarget": "my-app:build",
"proxyConfig": "proxy.conf.js"
},
"configurations": {
"production": {
"buildTarget": "my-app:build:production"
},
"development": {
"buildTarget": "my-app:build:development",
"proxyConfig": "proxy.conf.js"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "my-app:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
{
"glob": "favicon.ico",
"input": "src",
"output": "/"
},
{
"glob": "pdf.worker.min.mjs",
"input": "node_modules/pdfjs-dist/build/",
"output": "/assets/js/"
},
{
"glob": "**/*",
"input": "src/assets",
"output": "/assets"
}
],
"styles": [
"node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles/styles.scss"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "my-app:serve"
},
"configurations": {
"production": {
"devServerTarget": "my-app:serve:production"
}
}
}
}
}
},
"cli": {
"analytics": false
}
}
environment.ts (dev mode settings)
export const environment = {
production: false,
optimization: false,
apiHost: window.location.origin,
apiBaseUrl: '/api/v1',
baseUrl: '/',
hostName: window.location.host,
stompEndpoint: window.location.origin + '/stompEndpoint'
};
I upgraded to Angular 17 and now ng serve does not run in dev mode, no source map is available. I tried every possible solution I found online related to proxy config, package.json, angular.json. I finally made it at least run and load icons and fonts, but no source map, the console log prints true which means still in production mode despite all the config settings (console.info(environment.production);). Below my project files (confidential info is replaced)
Angular 17.3.12 Node.js 18.20.7
I tried different options and their combinations in all those files, a couple of different node.js versions. I tried using routing function in proxy config but that did not help either. By now, I think I included all possible options that are out there.
With current config settings, at least the page is rendered correctly, all icons, fonts are loaded. PDF file (EULA) is loaded. But it all seems are fetched from the remote server, not my local/dev environment. The dev tools do not show any local source files, no source code changes are reflected on a reload, even though it recognizes that changes did happen.
I spent almost two weeks trying to make it work. Any constructive solution would be truly appreciated. Thank you in advance!!!
PROXY.CONF.JS (I tried same in json format too, no difference)
var proxy_target = process.env.PROXY_TARGET || "1.2.3.4";
var PROXY_CONFIG = [
{
context: [
"/api",
"/rest"
],
target: "https://" + proxy_target + ":443",
secure: false,
optimization: false,
changeOrigin: true,
logLevel: "debug",
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization"
}
},
{
context: [
"/stompEndpoint"
],
target: "https://" + proxy_target + ":443",
secure: false,
optimization: false,
changeOrigin: true,
logLevel: "debug",
ws: true,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization"
}
},
{
context: ['/'],
target: "https://" + proxy_target + ":443",
secure: false,
optimization: false,
changeOrigin: true,
logLevel: "debug",
pathRewrite: {
"^/@fs/my/project/path/src/": "/",
"^/@fs/my/project/path/node_modules/pdfjs-dist/build/": "/assets/js/"
},
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization"
}
}
];
module.exports = PROXY_CONFIG;
--------------------------------------------------------
package.json
{
"name": "my-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.js --configuration=development --ssl true --open",
"serve": "ng serve",
"build": "ng build",
"watch": "ng build --watch",
"prod": "ng build --configuration production",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"pretty": "ng build --configuration production --optimization=false"
},
"private": true,
"dependencies": {
"@angular/animations": "17.3.12",
"@angular/cdk": "17.3.10",
"@angular/common": "17.3.12",
"@angular/compiler": "17.3.12",
"@angular/core": "17.3.12",
"@angular/flex-layout": "15.0.0-beta.42",
"@angular/forms": "17.3.12",
"@angular/material": "17.3.10",
"@angular/platform-browser": "17.3.12",
"@angular/platform-browser-dynamic": "17.3.12",
"@angular/router": "17.3.12",
"@ng-select/ng-select": "12.0.7",
"@xterm/xterm": "5.5.0",
"ajv": "8.8.2",
"async": "3.2.4",
"bufferutil": "4.0.6",
"d3": "7.8.2",
"date-fns": "2.16.1",
"eventsource": "2.0.2",
"jsplumbtoolkit": "file:./src/app/lib/jsplumbtoolkit.tgz",
"jsplumbtoolkit-drop": "file:./src/app/lib/jsplumbtoolkit-drop.tgz",
"jsplumbtoolkit-editable-connectors": "file:./src/app/lib/jsplumbtoolkit-editable-connectors.tgz",
"jsplumbtoolkit-labels": "file:./src/app/lib/jsplumbtoolkit-labels.tgz",
"jsplumbtoolkit-search": "file:./src/app/lib/jsplumbtoolkit-search.tgz",
"jsplumbtoolkit-undo-redo": "file:./src/app/lib/jsplumbtoolkit-undo-redo.tgz",
"lodash": "4.17.21",
"lodash-es": "4.17.21",
"ng-terminal": "6.4.0",
"ng2-pdf-viewer": "10.3.1",
"ngx-cookie-service": "17.1.0",
"ngx-webstorage-service": "4.1.0",
"node": "^20.9.0",
"npm-force-resolutions": "^0.0.10",
"pdfjs-dist": "4.6.82",
"rxjs": "6.5.5",
"sass": "1.43.5",
"tslib": "1.10.0",
"utf-8-validate": "5.0.9",
"xregexp": "5.1.1",
"zone.js": "0.14.10"
},
"devDependencies": {
"@angular-devkit/build-angular": "17.3.12",
"@angular/cli": "17.3.12",
"@angular/compiler-cli": "17.3.12",
"@eslint/config-array": "0.19.2",
"@eslint/object-schema": "2.1.6",
"@rollup/rollup-win32-x64-msvc": "4.35.0",
"@stomp/rx-stomp": "^1.1.4",
"@types/d3": "7.4.0",
"@types/jasmine": "4.0.3",
"@types/jasminewd2": "2.0.10",
"@types/lodash": "4.14.182",
"@types/node": "13.13.52",
"@xterm/addon-fit": "0.10.0",
"engine.io": "6.6.2",
"esbuild": "0.25.0",
"eslint": "9.21.0",
"jasmine-core": "4.3.0",
"jasmine-spec-reporter": "7.0.0",
"json5": "2.2.3",
"karma": "6.4.0",
"karma-chrome-launcher": "3.1.1",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-jasmine": "5.1.0",
"karma-jasmine-html-reporter": "2.0.0",
"loader-utils": "2.0.4",
"net": "1.0.2",
"sockjs-client": "1.6.1",
"ts-node": "10.9.1",
"typescript": "5.4.5",
"ua-parser-js": "0.7.34"
}
}
-------------------------------------------------------------------------
angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"my-app": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser-esbuild",
"options": {
"baseHref": "/",
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
{
"glob": "favicon.ico",
"input": "src",
"output": "/"
},
{
"glob": "pdf.worker.mjs",
"input": "node_modules/pdfjs-dist/build/",
"output": "/assets/js/"
},
{
"glob": "**/*",
"input": "src/assets",
"output": "/assets",
"ignore": ["**/media/**/*"]
}
],
"styles": [
"node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles/styles.scss"
],
"scripts": [],
"allowedCommonJsDependencies": [
"rxjs",
"angular2-uuid",
"xterm",
"pdfjs-dist/build/pdf",
"pdfjs-dist/web/pdf_viewer",
"lodash",
"jsplumbtoolkit-drop",
"jsplumbtoolkit",
"xterm-addon-fit",
"sockjs-client",
"xregexp"
],
"optimization": true
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "50mb",
"maximumError": "50mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
},
"development": {
"optimization": false,
"sourceMap": {
"scripts": true,
"styles": true,
"hidden": true,
"vendor": true
},
"namedChunks": true,
"extractLicenses": false,
"buildOptimizer": false,
"budgets": [
{
"type": "initial",
"maximumWarning": "30mb",
"maximumError": "50mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "20kb",
"maximumError": "40kb"
}
]
}
},
"defaultConfiguration": "development"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"buildTarget": "my-app:build",
"proxyConfig": "proxy.conf.js"
},
"configurations": {
"production": {
"buildTarget": "my-app:build:production"
},
"development": {
"buildTarget": "my-app:build:development",
"proxyConfig": "proxy.conf.js"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "my-app:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
{
"glob": "favicon.ico",
"input": "src",
"output": "/"
},
{
"glob": "pdf.worker.min.mjs",
"input": "node_modules/pdfjs-dist/build/",
"output": "/assets/js/"
},
{
"glob": "**/*",
"input": "src/assets",
"output": "/assets"
}
],
"styles": [
"node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles/styles.scss"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "my-app:serve"
},
"configurations": {
"production": {
"devServerTarget": "my-app:serve:production"
}
}
}
}
}
},
"cli": {
"analytics": false
}
}
environment.ts (dev mode settings)
export const environment = {
production: false,
optimization: false,
apiHost: window.location.origin,
apiBaseUrl: '/api/v1',
baseUrl: '/',
hostName: window.location.host,
stompEndpoint: window.location.origin + '/stompEndpoint'
};
Share
Improve this question
edited Mar 26 at 20:06
user30061734
asked Mar 26 at 17:32
user30061734user30061734
12 bronze badges
0
1 Answer
Reset to default 0I found some solution on Github and it worked for me as well. Not ideal, it seems working.
Replace 'browser-esbuild' with just 'browser' in angular.json:
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
本文标签:
版权声明:本文标题:angular17 - Angular 17, ng serve does not run in development mode, no source map - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744135508a2592378.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论