在工作区配置(src)中找不到项目主文件

问题描述 投票:0回答:2

我开始了一个在前端使用 Angular 17 的个人项目,并决定使用 ngx-bootstrap。 ngx-bootstrap 发布了一个与 Angular 17 兼容的版本([email protected])。但是在下载 ngx-bootstrap 时,我收到一条错误消息“无法在工作区配置(src)中找到项目主文件”。

$ ng add ngx-bootstrap
ℹ Using package manager: npm
✔ Found compatible package version: [email protected].
✔ Package information loaded.

The package [email protected] will be installed and executed.
Would you like to proceed? Yes
✔ Packages successfully installed.
    ✅️ Added "bootstrap
    ✅️ Added "ngx-bootstrap
Could not find the project main file inside of the workspace config (src)

folder structure

我尝试再次下载,但出现同样的错误。

angular ngx-bootstrap angular17
2个回答
1
投票

已经在

ngx-bootstrap
github 页面上创建了一个问题,所以你可以按照他们的建议使用
ng-bootstrap
,实际上效果很好!

这是破坏命令的

code
。似乎期望 app.module 而不是 main.ts

export function getProjectMainFile(project: workspaces.ProjectDefinition): string {
  const buildOptions = getProjectTargetOptions(project, 'build');
  if (!buildOptions.main) {
    throw new SchematicsException(`Could not find the project main file inside of the ` +
      `workspace config (${project.sourceRoot})`);
  }

  return buildOptions.main.toString();
}

如果你真的只想要 ngx-bootstrap,那么你需要手动安装它。这是安装指南


0
投票

这可能会晚一些,但对于 Angular 17,有一个快速修复方法: 在 angular.json 下,转到architect/build/options 并添加属性“main”并使其指向您的 main.ts ,如下所示:

"architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:application",
          "options": {
            "outputPath": "dist/client",
            "index": "src/index.html",
            "browser": "src/main.ts",
            "main": "src/main.ts", ... 

您会收到一条警告,指出这是不允许的,但只需重新运行 ng add ngx-bootstrap 即可正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.