Skip to content

🐛 Bug: "options.bin?.replace is not a function" when package.json bin is an object #2039

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

Closed
3 tasks done
JoshuaKGoldberg opened this issue Mar 27, 2025 · 1 comment · Fixed by #2040
Closed
3 tasks done
Assignees
Labels
status: accepting prs Please, send a pull request to resolve this! type: bug Something isn't working :(

Comments

@JoshuaKGoldberg
Copy link
Owner

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Expected

Running npx create-typescript-app should not crash on any valid package.json files.

Actual

Running on https://github.com/JoshuaKGoldberg/cspell-populate-words/tree/a84073d03e8517558269d567e9a47e9a87b4359e:

 npx create-typescript-app --add-cta-transitions

┌  ✨ [email protected] ✨
│
●  Learn more on:
│    https://github.com/JoshuaKGoldberg/create-typescript-app
│
◇  Running with mode --transition using the template:
│    create-typescript-app
│
│
◇  Detected --preset everything from existing files on disk.
│  
◇  Inferred options from existing repository
│
■  Error running create-typescript-app:
│
■  TypeError: options.bin?.replace is not a function
│      at Object.produce (file:///Users/josh/repos/create-typescript-app/lib/blocks/blockPackageJson.js:56:30)
│      at block.produce (file:///Users/josh/repos/create-typescript-app/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/bingo-stratum/lib/creators/createBlock.js:15:32)
│      at produceBlock (file:///Users/josh/repos/create-typescript-app/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/bingo-stratum/lib/producers/produceBlock.js:9:26)
│      at produceBlocks (file:///Users/josh/repos/create-typescript-app/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/bingo-stratum/lib/producers/produceBlocks.js:23:35)
│      at produceStratumTemplate (file:///Users/josh/repos/create-typescript-app/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/bingo-stratum/lib/producers/produceStratumTemplate.js:10:12)
│      at Object.produce (file:///Users/josh/repos/create-typescript-app/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/bingo-stratum/lib/creators/createStratumTemplate.js:72:20)
│      at produceTemplate (file:///Users/josh/repos/create-typescript-app/node_modules/.pnpm/[email protected]/node_modules/bingo/lib/producers/produceTemplate.js:15:35)
│      at runTemplate (file:///Users/josh/repos/create-typescript-app/node_modules/.pnpm/[email protected]/node_modules/bingo/lib/runners/runTemplate.js:18:28)
│      at async file:///Users/josh/repos/create-typescript-app/node_modules/.pnpm/[email protected]/node_modules/bingo/lib/cli/transition/runModeTransition.js:65:98
│      at async tryCatchError (file:///Users/josh/repos/create-typescript-app/node_modules/.pnpm/[email protected]/node_modules/bingo/lib/utils/tryCatch.js:3:16)
│
└  Leaving changes to the local directory on disk. 👋

Additional Info

cspell-populate-words has an object bin:

	"bin": {
		"cspell-populate-words": "bin/index.mjs"
	},

https://github.com/JoshuaKGoldberg/cspell-populate-words/blob/a84073d03e8517558269d567e9a47e9a87b4359e/package.json#L16-L18

@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Please, send a pull request to resolve this! type: bug Something isn't working :( labels Mar 27, 2025
@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Mar 27, 2025
JoshuaKGoldberg added a commit that referenced this issue Mar 27, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
## PR Checklist

- [x] Addresses an existing open issue: fixes #2039
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Updates the `PartialPackageData` type to note that `bin` could be a
`Record<string, string>`, not just a `string`. `blockPackageJson` will
collect its values if it is an object.

Also updates other references to `options.bin` to use a new
`getPrimaryBin` function for determining what the main runner is. Per
https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin using
the same name as the repo is equivalent to using a string.

🎁
Copy link

🎉 This is included in version v2.15.3 🎉

The release is available on:

Cheers! 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! type: bug Something isn't working :(
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant