Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Symlink to sap__types is deleted after each npm command #251

Closed
levkovsb opened this issue Sep 24, 2024 · 9 comments
Closed

[BUG] Symlink to sap__types is deleted after each npm command #251

levkovsb opened this issue Sep 24, 2024 · 9 comments
Assignees

Comments

@levkovsb
Copy link

levkovsb commented Sep 24, 2024

The issue persists in the version 0.6.5. As long as I execute any npm script in one of the workspaces of our monorepo, the symlink is gone and the project is no longer runnable. Please investigate further

Originally posted by @levkovsb in #216 (comment)

@daogrady
Copy link
Contributor

Hi @levkovsb ,

thanks for bringing this up again. Can you run npm rebuild in your repository and see if that recreates the symlink?

Best,
Daniel

@daogrady
Copy link
Contributor

daogrady commented Oct 2, 2024

@levkovsb also, can you please describe your setup in more detail or, preferably, provide a minimal reproduction setup? Is cds-types referenced in the mono repo root or in one of the subprojects?

@levkovsb
Copy link
Author

levkovsb commented Oct 7, 2024

@daogrady I have tried npm rebuild, it does not solve the issue. We have cds-types referenced in the package.json file in the monorepo root as a devDependency. There we also define our workspaces, e.g. "plugin/cross/*". Then in the plugin/cross/com folder we have its own package.json file that does not reference cds-types. The problem occurs when we run commands like npm publish.

@Markus-Schroeder-de
Copy link

Markus-Schroeder-de commented Oct 22, 2024

The symlink is often deleted. if i call mtb build, afterwards it is gone (because it calls npm i). "npm rebuild" does the magic.

@daogrady
Copy link
Contributor

daogrady commented Oct 24, 2024

Hi @levkovsb ,

as @Markus-Schroeder-de suggested, you can try npm rebuild to see if that fixes the symlink.
Could you elaborate why you don't just reference @cap-js/cds-types in each project's devDependency list?

Best,
Daniel

@ZhongpinWang
Copy link

ZhongpinWang commented Nov 11, 2024

Hi @daogrady ,

Thanks for pointing me to this issue. We are facing the same issue. I have already written the description in #294 (comment). Check also the Known Issue section -> SAP/ai-sdk-js#273

But just for a quick summary also here. We sometimes face the following problem:

Could not find a declaration file for module '@sap/cds'. '****/ai-sdk-js/node_modules/.pnpm/@[email protected][email protected]/node_modules/@sap/cds/lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/sap__cds` if it exists or add a new declaration (.d.ts) file containing `declare module '@sap/cds';`ts(7016)

This error is flaky. I am not sure when will this happen. But maybe by deleting the node_modules and try pnpm install can trigger this. (I suppose both pnpm and npm have the same problem). With a pnpm rebuild, the problem is gone.

Also sometimes, a fresh install in our pipeline works, but sometimes the symlink is missing. Re-trigger the pipeline and the problem can sometimes be gone.

We are also maintaining multiple packages in one repo. The interesting thing I find is that putting @cap-js/cds-types as devDependencies in one package will actually result into a symlink in the root node_modules, which sometimes links to nowhere.

Hope this issue can be resolved soon.

@hakimio
Copy link
Contributor

hakimio commented Nov 11, 2024

Might be an issue with the way pnpm sets INIT_CWD environment variable: pnpm/pnpm#7042
Also, experienced this issue where cds types could no longer be found after migrating from yarn monorepo to pnpm monorepo.
As a temporary workaround, I've added cap-js/cds-types to tsconfig:

{
    "compilerOptions": {
        /* ... */
        "types": [
            "./typings.d.ts",
            "@cap-js/cds-types"
        ]
    }
}

@daogrady
Copy link
Contributor

Hi @ZhongpinWang ,

I checked your repository and the similarity with @levkovsb seems to be that you are also using a monorepo.
So same question here: you do not reference @cap-js/cds-types in each workspace. Could you try specifying @cap-js/cds-types as dependency and try again? The dependency can be very lax, e.g. "@cap-js/cds-types": "*".

Best,
Daniel

P.S.: in the meanwhile, the suggestion @hakimio brought up is a perfectly valid solution.

@daogrady
Copy link
Contributor

Closing as quasi-duplicate of #318

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants