cap-js / cds-typer

CDS type generator for JavaScript
Apache License 2.0
29 stars 10 forks source link

[BUG] Path with spaces crash the type generation process in SAP BAS. #330

Closed mrbryo closed 2 months ago

mrbryo commented 2 months ago

Is there an existing issue for this?

Nature of Your Project

JavaScript

Current Behavior

CDS Output from building the CAP v8 Project:

CDSError: Could not (re)generate types for model. Could not read file content of *: Failed: node "/home/user/projects/zcfglobalapp/node_modules/@cap-js/cds-typer/lib/cli.js" "*" --outputDirectory "/home/user/projects/zcfglobalapp/gen/srv/@cds-models"
<exit code:>
1
<stderr:>
node:internal/bootstrap/switches/does_own_process_state:144
    cachedCwd = rawMethods.cwd();
                           ^

Error: ENOENT: no such file or directory, uv_cwd
    at process.wrappedCwd [as cwd] (node:internal/bootstrap/switches/does_own_process_state:144:28)
    at <instance_members_initializer> (/home/user/projects/zcfglobalapp/node_modules/@sap/cds/lib/index.js:17:37)
    at new cds (/home/user/projects/zcfglobalapp/node_modules/@sap/cds/lib/index.js:9:47)
    at Object.<anonymous> (/home/user/projects/zcfglobalapp/node_modules/@sap/cds/lib/index.js:9:43)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:179:18) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'uv_cwd'
}

Node.js v20.12.0

Expected Behavior

No Errors

Steps To Reproduce

Build a CAP project in Business Application Studio.

Environment

- **OS**: Linux?
- **Node**: 20.12.0
- **npm**: 10.5.0
- **cds-typer**: 0.26
- **cds**: 8.1

Repository Containing a Minimal Reproducible Example

No response

Anything else?

No response

mrbryo commented 2 months ago

I did find old bug report 138 and that fix is in place still.

daogrady commented 2 months ago

Hi Brian,

thanks for opening this issue! Just for clarity:

I did find old bug report 138 and that fix is in place still.

Do you mean the bug still exists or the fix described in https://github.com/cap-js/cds-typer/issues/138 still works?

Best, Daniel

mrbryo commented 2 months ago

I think the bug still exists or something related to it. The fix in that 138 ticket is in place but yet I get the same error.

daogrady commented 2 months ago

Hi Brian,

I see that the error apparently comes up when running cds build. I have added a fix that quotes the path of the output directory in cds-typer's build task, which should hopefully resolve the error and will be included in the next release.

Still, I have two questions:

  1. the error you showed does not contain any spaces in the project path. Is that the actual path or did you obfuscate the name?
  2. spaces in project names are quite unusual and any call to cds init that would create a project with a space in its name will usually fail. So I guess you deliberately renamed the project after its creation. I can imagine a few scenarios in which you would need spaces in your project's path, like company policy, auto-generated user names, etc, but in any other case I would like to recommend using a space-less project name.

Best, Daniel

mrbryo commented 2 months ago

Hi Daniel,

Nothing obfuscated. I haven't renamed the project. BTW, should have said in the initial creation of this ticket, this is all done in SAP Build Code. The versions indicated are what Code setup. I did notice after creating the project, while I was creating the entities I was getting some CDS errors about cds-typer missing.

TyperNotInstalledError: Will not attempt to generate types as the type generator is not installed in your CDS project. Install @cap-js/cds-typer as dependency of your project to enable type generation for this project

Even after building I'm getting the above error. I haven't modified the package.json to remove or add cds-typer library like we do when setting up a regular CAPM project in BAS. I'm trying to stick with what the default setup in Build Code provides.

Thanks, Brian

daogrady commented 2 months ago

Hi Brian,

then I am actually confused as to how you ended up with a project with a space in it. 🤔

Regarding the other issue you found: how did you introduce cds-typer into your project?

Best, Daniel

mrbryo commented 2 months ago

Hey Daniel,

Where is there a space? Oh, just realized, I think I may have pasted the title from the other ticket I've referenced. Sorry for the confusion. I'm just getting the same error as the other ticket but there is no space in the project name. But after an initial build it looks like it has resolved itself. When I build now that error isn't showing up.

I haven't introduced cds-typer at all. I was trying to use SAP Build Code as is and not modify the package.json file to let Build Code manage it. Should I open a different issue? Or can you tell me if I'm expected to add cds-typer myself?

Sorry for the confusion, Brian

daogrady commented 2 months ago

Hi Brian,

no worries, that clears up some of the confusion!

I haven't introduced cds-typer at all.

If I am not mistaken, the issue appears when you execute cds build. That implies that cds-typer is present in your project. cds-typer is usually introduced to your project by executing cds add typer. We still only put it into your package.json for you, so you still have to install it manually, as we do not want to execute npm i for you.

We do not have a dedicated BAS section in CAPire, but most of the VSCode section in the doc also applies.

Let me know if that helps.

Best, Daniel

mrbryo commented 2 months ago

Hey Daniel,

OK I'll use the cds add typer, I figured Build Code had a way to do it itself. My team is just starting to use the tool and learn it compared to just "regular" BAS.

Thanks! Brian

daogrady commented 2 months ago

Hi Brian,

great! Still, I'd like to note that cds-typer is actually an optional tool that improves code completion for JavaScript projects and type information for TypeScript projects. It is not strictly needed, so your mileage may vary.

If you run into any more problems with cds-typer, feel free to open another ticket here.

Best, Daniel