Closed blefnk closed 5 months ago
Hi, thank you!
I cannot reproduce this:
coderaiser@localcmd:~/Amber$ cat > 1.js
var a = 5;
^C
coderaiser@localcmd:~/Amber$ npx putout 1.js
1.js
1:4 error 'a' is defined but never used remove-unused-variables
β 1 errors in 1 files
fixable with the `--fix` option
but there is a couple places where bug can occur: https://github.com/search?q=repo%3Acoderaiser%2Fputout%20name.startsWith&type=code.
Could you please provide more details? Maybe you can add console.log
to identify problem place?
@coderaiser Thanks for your response! Yes, of course, I plan to do it on Tuesday. I also plan to try to build Putout on my own. I will also try to run it on my other laptop with Windows 11. I will get back to you once I manage to explore a bit more details. Thank you for the search link π
Just fixed similar bug in πPutout v35.35.5. Could you please tell me if it works for you?
devDependencies:
- putout 35.35.4
+ putout 35.35.5
> pnpm putout test.js
π name.startsWith is not a function
> pnpm dlx putout@latest test.js
π name.startsWith is not a function
> npm run putout test.js
π name.startsWith is not a function
> npx putout@latest test.js
π name.startsWith is not a function
// without .putout.json
npx putout@latest test.js
π No processors found for test.js
bun add -D putout@latest
installed putout@35.35.5 with binaries: putout
> bun putout index.js
$ putout index.js
π name.startsWith is not a function
error: script "putout" exited with code 9
.putout.json
bun add -D putout@latest
installed putout@35.35.5 with binaries: putout
> bun putout index.js
$ putout index.js
node:internal/event_target:1094
process.nextTick(() => { throw err; });
^
Error: Cannot find module './url'
Require stack:
- C:\B\S\putout-minimal-repro\node_modules\source-map\lib\util.js
- C:\B\S\putout-minimal-repro\node_modules\source-map\lib\source-map-generator.js
- C:\B\S\putout-minimal-repro\node_modules\source-map\source-map.js
- C:\B\S\putout-minimal-repro\node_modules\recast\lib\util.js
- C:\B\S\putout-minimal-repro\node_modules\recast\lib\options.js
- C:\B\S\putout-minimal-repro\node_modules\recast\lib\parser.js
- C:\B\S\putout-minimal-repro\node_modules\recast\main.js
- C:\B\S\putout-minimal-repro\node_modules\@putout\engine-parser\lib\print.js
- C:\B\S\putout-minimal-repro\node_modules\@putout\engine-parser\lib\parser.js
- C:\B\S\putout-minimal-repro\node_modules\putout\lib\putout.js
- C:\B\S\putout-minimal-repro\node_modules\putout\lib\cli\process-file.js
- C:\B\S\putout-minimal-repro\node_modules\putout\lib\cli\runner\runner.js
- C:\B\S\putout-minimal-repro\node_modules\putout\lib\cli\index.js
at Function._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Function._load (node:internal/modules/cjs/loader:986:27)
at Module.require (node:internal/modules/cjs/loader:1233:19)
at require (node:internal/modules/helpers:179:18)
at Object.<anonymous> (C:\B\S\putout-minimal-repro\node_modules\source-map\lib\util.js:8:13)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Object..js (node:internal/modules/cjs/loader:1416:10)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Function._load (node:internal/modules/cjs/loader:1024:12)
at Module.require (node:internal/modules/cjs/loader:1233:19)
Emitted 'error' event on Worker instance at:
at [kOnErrorMessage] (node:internal/worker:326:10)
at [kOnMessage] (node:internal/worker:337:37)
at MessagePort.<anonymous> (node:internal/worker:232:57)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:820:20)
at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\B\\S\\putout-minimal-repro\\node_modules\\source-map\\lib\\util.js',
'C:\\B\\S\\putout-minimal-repro\\node_modules\\source-map\\lib\\source-map-generator.js',
'C:\\B\\S\\putout-minimal-repro\\node_modules\\source-map\\source-map.js',
'C:\\B\\S\\putout-minimal-repro\\node_modules\\recast\\lib\\util.js',
'C:\\B\\S\\putout-minimal-repro\\node_modules\\recast\\lib\\options.js',
'C:\\B\\S\\putout-minimal-repro\\node_modules\\recast\\lib\\parser.js',
'C:\\B\\S\\putout-minimal-repro\\node_modules\\recast\\main.js',
'C:\\B\\S\\putout-minimal-repro\\node_modules\\@putout\\engine-parser\\lib\\print.js',
'C:\\B\\S\\putout-minimal-repro\\node_modules\\@putout\\engine-parser\\lib\\parser.js',
'C:\\B\\S\\putout-minimal-repro\\node_modules\\putout\\lib\\putout.js',
'C:\\B\\S\\putout-minimal-repro\\node_modules\\putout\\lib\\cli\\process-file.js',
'C:\\B\\S\\putout-minimal-repro\\node_modules\\putout\\lib\\cli\\runner\\runner.js',
'C:\\B\\S\\putout-minimal-repro\\node_modules\\putout\\lib\\cli\\index.js'
]
}
Node.js v20.15.0
error: script "putout" exited with code 1
Could you please try to pass β-raw
flag when running πPutout and check ~/.putout.json
in your home directory, looks like issue with configuration file, but Iβm not sure what exactly issue is.
I couldn't find .putout.json
in my C:\Users\blefn
home folder, subfolders there doesn't has this file as well. I just tried to create such a file myself, but unfortunately, the result is the same, with and without --raw
flag.
> pnpm putout test.js --raw || pnpm dlx putout test.js --raw || npx putout test.js --raw
π name.startsWith is not a function
error: "putout.cmd" exited with code 9
Yeah, hooray! This almost resolved the issue! π
Now putout
works successfully as long as the putout
dependency is not installed.
devDependencies:
- putout 35.35.6
However, if it is installed, it seems to "think" that it is part of the original monorepo and expects all its dependencies to be in the project, and since they are not, we get π No processors found for test.js
(or also π name.startsWith is not a function
).
So, theoretically, if all the necessary dependencies are installed, it should work. Maybe itβs necessary to add some peer dependencies to package.json
binaries for putout
? I mean, so that all the necessary dependencies of putout
are installed together with putout
. Or, is this already being done?
So currently, as a temporary solution, I added the following to scripts
of package.json
file: "putout": "pnpm dlx putout@latest"
, which makes pnpm putout test.js
work successfully. This works both with and without a config.
upd. It turned out π name.startsWith is not a function
is still present if .putout.json
contains "formatter": [{ "minCount": 10 }, "progress-bar" ]
. This happens even with pnpm dlx putout@latest
.
It also turned out that when using pnpm dlx putout@latest
, it is impossible to install custom processors. For example, when using "processors": ["javascript", "typescript"]
, I get π Cannot find package 'putout-processor-typescript'
, even though @putout/processor-typescript
is installed. I have a theory that the config tries to refer to the putout
library first, but it is not installed locally. Or maybe the problem is that it searches for the dependency "putout-processor-typescript" while the actual package is named @putout/processor-typescript
? Hmm... π€
p.s. I also tried testing putout
on Linux Mint, and to my great surprise, it turned out that π name.startsWith is not a function
is not a Windows-specific issue; it is also present on Linux (and presumably on macOS, I guess).
upd. So strange, but it seems that everything works now when "formatter": [{ "minCount": 10 }, "progress-bar" ]
is set. So this specific issue may be was solved.
Looks like name.startsWith is not a function
is pnpm
-specific issue. Try to use bun
to install dependencies. Also you can create issue in pnpm
repository.
I cannot reproduce this with pnpm
:
coderaiser@localcmd:~/putout$ cat > 1.js
const a = 'hello';
^C
coderaiser@localcmd:~/putout$ pnpm dlx putout@latest 1.js
1.js
1:6 error 'a' is defined but never used remove-unused-variables
β 1 errors in 1 files
fixable with the `--fix` option
If you have any ideas how to reproduce - you can send PR with test, I'll merge so it work for your case.
I have completed the investigation. It turned out that the latest issues were due to the fact that if there is a key-value pair in .putout.json
that expects the presence of another key-value pair but does not find it, a problem occurs. That's why the formatter worked for me in the end, as I copy-pasted the entire putout.json
from your monorepo. This issue also arises if there is incorrect sorting of key-value pairs. As a solution, a .js/.ts/.mjs config could be implemented in addition to json. So issue is not related to specific package manager or OS.
Could you please provide an example of broken config? Just copied putout.json
from monorepo and still cannot reproduce. Maybe link to minimal repository can help.
I suggest you to always install πPutout as devDependency
, if you install it as global, and run it as global, additional processors (like @putout/processor-typescript
) should be also installed globally. devDependency
is convinient and recommended way to install and run πPutout.
Hello, guys! Putout looks incredible, I regret not hearing about it earlier! You've done a great job!
However, unfortunately, I've encountered a strange issue. When I run
npx putout test.js
orpnpm putout test.js
, I getπ name.startsWith is not a function
. I've tried several of the latest versions, and this error appears starting from v31.0.0. Versions up to v30.7.0 give the errorπ Cannot find package 'putout-formatter-[object Object]'
. Interestingly, version v35.35.4 does not produce any output, buttest.js
(the example from your README.md) still doesn't change.I'm using Node.js LTS (v20.15.0), and I tested the previous LTS (v18.20.3) β the error is there as well. I think it might be an issue with pnpm, but the same happens with npm and bun (including pnpm dlx, npx, bunx).
I tested both with and without a Putout config (with the full code from the repo and with just processors with javascript). I tried both a clean
pnpm create next-app
andbun init
. I tried running it in PowerShell, CMD, Git Bash. In the VSCode terminal and in external ones.Please let me know if I can provide any additional information, I will do my best and would be happy to help in any way I can.
Thanks for this wonderful tool! It's really cool!