Skip to content

Running with a project that uses yarn creates a package-lock.json file #560

Description

@gugahoi

It seems like this script does not respect projects that use yarn and instead will always create a package-lock file. Here is the outcome from running it on my project:

➜ npx api install @basiq/v3.0#73eilabzsv3b
✔ What language would you like to generate an SDK for? › TypeScript
✔ Fetching your API
✔ Generating your SDK
✔ Saving your SDK into your codebase
⚠ This generator requires some packages to be installed alongside it:
  › api: Required for the `api/dist/core` library that the codegen''d SDK uses for making requests. https://npm.im/api
  › json-schema-to-ts: Required for TypeScript type handling. https://npm.im/json-schema-to-ts
  › oas: Used within `api/dist/core` and is also loaded for TypeScript types. https://npm.im/oas
✔ OK to proceed with package installation? … yes
✔ Installing required packages
🚀 All done!


➜ git status                            
On branch basiq-connect
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   yarn.lock

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.api/
	package-lock.json

no changes added to commit (use "git add" and/or "git commit -a")

I am not sure why the package-lock.json file is there at all - I don't think it will do anything since I am using yarn.

Furthermore I also am not sure how I would go about importing the downloaded SDK. I can see the files under ./.api but there is nothing in the documentation instructing me on how to consume them. Do I need to add a local file entry to package.json?

➜ tree -L 3 .api 
.api
├── api.json
└── apis
    └── basiq
        ├── index.ts
        ├── node_modules
        ├── openapi.json
        ├── package-lock.json
        ├── package.json
        ├── schemas.ts
        └── types.ts

Activity

  1. self-assigned this
    on Nov 23, 2022
  2. added
    area:api
    enhancement
    good first issue
    on Nov 23, 2022
  3. erunion commented on Nov 25, 2022

    @erunion
    Member

    api currently doesn't support Yarn but it's on our immediate roadmap.

    Furthermore I also am not sure how I would go about importing the downloaded SDK. I can see the files under ./.api but there is nothing in the documentation instructing me on how to consume them. Do I need to add a local file entry to package.json?

    There was actually a bug that was preventing the installed API in .api/.apis/ from being hooked up into your package.json. If you re-install that API @api/basiq will be added to your package.json so you can import it.

  4. gugahoi commented on Nov 28, 2022

    @gugahoi
    Author

    Thanks for fixing the consumption part, however I am still having some problems and I am not sure if they are due to the API spec that I am trying to consume or something missing from this package. Following is the terminal output:

    ➜ npx api install @basiq/v3.0#73eilabzsv3b
    Need to install the following packages:
      api
    Ok to proceed? (y) 
    ✔ What language would you like to generate an SDK for? › TypeScript
    ✔ Fetching your API
    ✔ Generating your SDK
    ✔ Saving your SDK into your codebase
    ⚠ This generator requires some packages to be installed alongside it:
      › api: Required for the `api/dist/core` library that the codegen'd SDK uses for making requests. https://npm.im/api
      › json-schema-to-ts: Required for TypeScript type handling. https://npm.im/json-schema-to-ts
      › oas: Used within `api/dist/core` and is also loaded for TypeScript types. https://npm.im/oas
    ✔ OK to proceed with package installation? … yes
    ✔ Installing required packages
    🚀 All done!
    
    flux/packages/api-service …
    ✘130 ➜ yarn    
    yarn install v1.22.18
    warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
    [1/4] 🔍  Resolving packages...
    error Can't add "@api/basiq": invalid package version "".
    info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
    
    flux/packages/api-service …
    ✘1 ➜ rm package-lock.json 
    
    flux/packages/api-service …
    ➜ yarn
    yarn install v1.22.18
    [1/4] 🔍  Resolving packages...
    error Can't add "@api/basiq": invalid package version "".
    info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
    

    As you can see, yarn complains about the installed api sdk due to a missing version. I can manually rectify this locally but I don't think this is the correct way to approach this. Is the problem on my end? On the API spec I am consuming? Or is this still a bug?

  5. erunion commented on Nov 28, 2022

    @erunion
    Member

    Seems this is happening because we aren't setting a version property in the package.json we create for the installed API in the .apis/ directory. I'll get a fix going for this.

  6. erunion commented on Nov 28, 2022

    @erunion
    Member

    @gugahoi That issue should now be resolved in v5.0.3.

    I'll see if I can carve out some time this week to prioritize Yarn support.

  7. haltcase commented on Dec 2, 2022

    @haltcase

    @erunion similarly, it would be nice to have support for pnpm, but it could be more complicated. What ended up working for me as a workaround was to:

    1. Execute pnpm dlx api install @render-api/v1.0#f084kp1glacw8qb7 and say yes to package installation
    2. Cancel once the .api/apis/render-api/package.json file is updated with dependencies ( this wasn't perfect — I had to manually add openapi-types as it was missing, might have been timing but I'm not sure yet )
    3. Create pnpm-workspace.yaml (pnpm doesn't handle dependency installation well for locally linked packages)
      packages:
        - ".api/apis/*"
    4. Add the api package as a workspace dependency in the root package.json
      "dependencies": {
      	"@api/render-api": "workspace:*"
      }
    5. Run pnpm install and the package should be importable now

    However, I wonder if it would be worth looking into how Prisma generates its client since that works rather well across package managers in my experience. You'd have to regenerate the API package in fresh directories though (since it's dropped into node_modules).

  8. added this to the v7 milestone on Oct 6, 2023
  9. erunion commented on Oct 18, 2023

    @erunion
    Member

    Dug into this a bit after discovering preferred-pm and that's got a pretty big blocker for us where if we you run npx api install from inside of an NPM workspace directory like packages/client it thinks you use Yarn. I've filed the bug to zkochan/packages#180 but am unfortunately going to have to put Yarn and pnpm on hold until that's sorted out.

  10. removed this from the v7 milestone on Oct 18, 2023
  11. added
    help wanted
    on Oct 18, 2023
  12. removed their assignment
    on Oct 19, 2023
  13. EugenGedroyc commented on Jan 25, 2024

    @EugenGedroyc
    Contributor

    I use ynpx and get the same problems

    I've filed the bug to zkochan/packages#180

    answer received

  14. phorcys420 commented on Jan 21, 2025

    @phorcys420

    Dug into this a bit after discovering preferred-pm and that's got a pretty big blocker for us where if we you run npx api install from inside of an NPM workspace directory like packages/client it thinks you use Yarn. I've filed the bug to zkochan/packages#180 but am unfortunately going to have to put Yarn and pnpm on hold until that's sorted out.

    While this issue seems to have been fixed, I think you might be better off by relying on Corepack's packageManager field in the package.json.
    If you don't use Corepack, it's harmless, and it's a pretty simple config too.


    For context, I'm running into this issue with Bun by using bunx (npx equivalent).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apienhancementgood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions