gpt4 book ai didi

angular - 如何修复 : Data path "" should have required property 'browserTarget' error in Angular 8 when running ng serve or npm start

转载 作者:行者123 更新时间:2023-12-03 21:01:10 28 4
gpt4 key购买 nike

我正在尝试运行“ng serve”或“npm start”以在 Windows 机器上的 cmd 中的 localhost:4200 上运行我的 angular 8 服务器。我收到 Schema 错误,我想我知道问题出在哪里,但不知道如何解决。

需要注意的另一点是,在 Windows 重新启动我的计算机进行更新之前,这一切正常。

我也在通过 webpack 运行顺风。

错误的主要部分是:数据路径“”应该具有必需的属性“browserTarget”

"serve": {
"builder": "@angular-builders/custom-webpack:dev-server",
"options": {
"customWebpackConfig": {
"path": "./webpack.config.js"
}
}
},

我假设我需要在此处的选项中添加 browserTarget,当我这样做时,我收到一条错误消息,说我也需要 main 。

我在正确的轨道上吗?
如果我是,应该赋予这些属性的值(value)是什么?

任何帮助将不胜感激。

我试过了:
  • 升级我的包。
  • 升级 Angular
  • 删除节点模块文件夹和 npm 安装

  • Angular .json:

    {
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
    "bjjcastle": {
    "projectType": "application",
    "schematics": {
    "@schematics/angular:component": {
    "style": "scss"
    }
    },
    "root": "",
    "sourceRoot": "src",
    "prefix": "app",
    "architect": {
    "build": {
    "builder": "@angular-builders/custom-webpack:browser",
    "options": {
    "customWebpackConfig": {
    "path": "./webpack.config.js"
    }
    }
    },
    "serve": {
    "builder": "@angular-builders/custom-webpack:dev-server",
    "options": {
    "customWebpackConfig": {
    "path": "./webpack.config.js"
    }
    }
    },
    "extract-i18n": {
    "builder": "@angular-devkit/build-angular:extract-i18n",
    "options": {
    "browserTarget": "bjjcastle: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": [
    "src/favicon.ico",
    "src/assets"
    ],
    "styles": [
    "src/styles.scss",
    "node_modules/font-awesome/scss/font-awesome.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": "bjjcastle:serve"
    },
    "configurations": {
    "production": {
    "devServerTarget": "bjjcastle:serve:production"
    }
    }
    }
    }
    }},
    "defaultProject": "bjjcastle"
    }


    包.json:

    {
    "name": "bjjcastle",
    "version": "0.0.0",
    "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
    },
    "private": true,
    "dependencies": {
    "@angular/animations": "~8.2.2",
    "@angular/common": "~8.2.2",
    "@angular/compiler": "~8.2.2",
    "@angular/core": "~8.2.2",
    "@angular/forms": "~8.2.2",
    "@angular/platform-browser": "~8.2.2",
    "@angular/platform-browser-dynamic": "~8.2.2",
    "@angular/router": "~8.2.2",
    "@fortawesome/angular-fontawesome": "^0.5.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.21",
    "@fortawesome/free-brands-svg-icons": "^5.10.1",
    "@fortawesome/free-solid-svg-icons": "^5.10.1",
    "rxjs": "~6.5.2",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
    },
    "devDependencies": {
    "@angular-builders/custom-webpack": "^8.1.0",
    "@angular-devkit/build-angular": "~0.802.2",
    "@angular/cli": "~8.2.2",
    "@angular/compiler-cli": "~8.2.2",
    "@angular/language-service": "~8.2.2",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "postcss-import": "^12.0.1",
    "postcss-loader": "^3.0.0",
    "postcss-scss": "^2.0.0",
    "protractor": "~5.4.0",
    "tailwindcss": "^1.1.1",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
    }
    }


    webpack.config.js:

    module.exports = {
    module : {
    rules: [
    {
    test : /\.scss$/,
    loader : 'postcss-loader',
    options: {
    ident : 'postcss',
    syntax: 'postcss-scss',
    plugins: () => [
    require('postcss-import'),
    require('tailwindcss'),
    require('autoprefixer'),
    ]
    }
    }
    ]
    }
    };

    我收到的错误:
        Schema validation failed with the following errors:

    Data path "" should have required property 'browserTarget'.

    npm ERR! code ELIFECYCLE

    npm ERR! errno 1

    npm ERR! bjjcastle@0.0.0 start: `ng serve`

    npm ERR! Exit status 1


    npm ERR!

    npm ERR! Failed at the bjjcastle@0.0.0 start script.

    npm ERR! This is probably not a problem with npm. There is likely additional
    logging output above.

    npm ERR! A complete log of this run can be found in:

    npm ERR! C:\Users\MyRoute\AppData\Roaming\npm-cache\_logs\2019-08-16T05_27_51_621Z-debug.log

    最佳答案

    我遇到了同样的问题,将 angular/cli 更新到最新版本对我有帮助。
    在命令行中输入:
    ng更新@angular/cli

    关于angular - 如何修复 : Data path "" should have required property 'browserTarget' error in Angular 8 when running ng serve or npm start,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57519454/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com