FoalTS / foal

Full-featured Node.js framework, with no complexity. 🚀 Simple and easy to use, TypeScript-based and well-documented.
https://foalts.org/
MIT License
1.9k stars 140 forks source link

Error with FOAL CONNECT for angular>13 (project) : foal connect angular frontend_dir #1197

Closed Gfoulon closed 11 months ago

Gfoulon commented 1 year ago

Version of FoalTS: 3.1.0

First of all : FoalTS is really great!

I faced the following error when I try to connect an angular frontend project to FOAL, I've got the following error:

config.projects[config.defaultProject].architect ||= {};
TypeError: Cannot read properties of undefined (reading 'architect')

If I understand well config.defaultProject has been removed from Angular.json since Angular v14. (found on angular-cli : defaultProject deprecated [https://github.com/angular/angular-cli/issues/23470])

I found a solution which works for me (on IONIC projects), but not sure that's the best way to solve the issue:

In node_modules\@foal\cli\lib\generate\generators\angular\connect-angular.js :

    if (config.defaultProject === undefined) {
        console.log("NO default project (Angular>14 - use firstproject 'app'?) => ",angularProject);
    }
    config.projects[angularProject].architect ||= {};
    config.projects[angularProject].architect.serve ||= {};
    config.projects[angularProject].architect.serve.options ||= {};
    config.projects[angularProject].architect.serve.options.proxyConfig = 'src/proxy.conf.json';
    // Output build directory
    const outputPath = (0, path_1.join)((0, path_1.relative)(path, process.cwd()), 'public')
        // Make projects generated on Windows build on Unix.
        .replace(/\\/g, '/');
    config.projects[angularProject].architect.build ||= {};
    config.projects[angularProject].architect.build.options ||= {};
    config.projects[angularProject].architect.build.options.outputPath = outputPath;
    return JSON.stringify(config, null, 2);

Hope this could help.

LoicPoullain commented 1 year ago

Hi @Gfoulon 👋

First of all : FoalTS is really great!

Thank you!

I faced the following error when I try to connect an angular frontend project to FOAL, I've got the following error:

Do you want to submit a PR to fix this? The command foal connect command should always support the latest version of the CLI (Angular, Vue, etc) (not the previous ones).

The files to change are located in:

LoicPoullain commented 11 months ago

The bug has been fixed in #1236. The fix will be released with v4.2.

Thank you for reporting the issue and for the suggestion proposal 👍