Playwright giving "npm ERR! could not determine executable to run" failure - npm

Just started playing with Playwright. Installed and decided to run the tests that come with it. Can't figure out why it is failing.
$ npx playright tests
[11:09:04]
npm ERR! could not determine executable to run
FAIL
I've double check Typescript installed
$ tsc -v
Version 4.7.4
and nom
$ npm -v
8.1.0
I looked up solution on this site, and it mentions removing the .git/hooks file - I don't have that.
package.json is straight forward:
{
"name": "project01",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"author": "",
"license": "ISC",
"devDependencies": {
"#playwright/test": "^1.25.2"
}
}
What on earth am I missing? Did a lot of Googling and still stuck.
Any help would be appreciated.

Base on my experience, npx command was not recognized as executable command.
I tried changing to npm playwright install and it worked.
enter image description here

So, I'm not sure what happened, but when I tried a new project and followed the same steps, everything worked fine.
I guess the takeaway is, if this happens, try re-installing ¯_(ツ)_/¯

Related

Why npm keep asking me for license information even though it set "UNLICENSED"?

I have already set the package.json with following code for my company private project.
{
...
"license": "UNLICENSED",
"private": true,
...
}
but npm seems not giving up asking me for the license.
yarn run v1.22.19
warning ../../../package.json: No license field
Thanks comment from #jonrsharpe.
I found the package.json actually from different path, which is actually from ~/ path. For visual studio command, when I click the link it prompt, it actually jump to current path package.json file. That's why it confused me.

Yarn script fails when invoking other Yarn-scripts

I've got an issue when invoking other Yarn scripts from a Yarn-script. What I want to achieve is having one yarn develop task that first invokes TypeScript and some other preprocessors before starting a couple of watchers and running my application. I'd like to use npm-run-all (or something similar) to invoke multiple targets as that would allow me to define separate targets that I can manually run as well without having duplicate script-entries in my package.json.
I've made a minimal reproduction case which has the following package.json:
{
"name": "test",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"task:one": "echo one",
"task:two": "echo two",
"run-all": "npm-run-all task:one task:two",
"run-all-yarn": "yarn task:one && yarn task:two"
},
"devDependencies": {
"npm-run-all": "^4.1.5"
}
}
Invoking yarn task:one results in an echo one as expected, as does yarn task:two. If I invoke yarn run-all though, I get an error:
$-> yarn run-all
yarn run v1.22.10
$ npm-run-all task:one task:two
$ echo one
error Couldn't find the binary echo one
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "task:one" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
yarn run-all-yarn fails with (almost exactly, sans the command being executed on the second line) the same error.
If instead of Yarn I use NPM (npm run run-all) it all works as expected:
$-> npm run run-all
> test#1.0.0 run-all /Users/basdalenoord/Projects/52DN/psyflix/test
> npm-run-all task:one task:two
> test#1.0.0 task:one /Users/basdalenoord/Projects/52DN/psyflix/test
> echo one
one
> test#1.0.0 task:two /Users/basdalenoord/Projects/52DN/psyflix/test
> echo two
two
I'm using Yarn version 1.22.17 provided by my node-version from nvm: ~/.nvm/versions/node/v14.18.1/bin/yarn
I'm a bit lost as to why running individual targets would be fine but combining them fails for yarn, whereas the same script works for npm.

trouble with npm preinstall script

I'm trying to make the jump to pnpm from npm. I found a helpful hint to keep from running "npm install" after I make the change as described here: https://pnpm.js.org/en/only-allow-pnpm
Unfortunately my preinstall lifecycle override doesn't get executed. Seems to simple enough but npm install still works when I run something like "npm install #types/jest"
package.json:
{
"name": "react-sandbox",
"version": "0.1.0",
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm"
}
}
npm version 6.14.2.
Any ideas?
Unfortunately, the preinstall script is executed only during argumentless installation. So when you run npm add #types/jest, that script will not be executed, thus npm won't be prevented from running.
But it will fail when running npm install.
As of now, there is no other way to prevent npm from execution.

How to do npm scripts work vs direct commands?

I keep seeing this behavior, so I want to understand it. I install gulp and the gulp-cli (not globally). Typing the gulp command gives me -bash: gulp: command not found
I take the gulp command and drop it into an npm script and boom, it works. Can someone explain what's going on here?
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"gulp": "gulp", // This works!!
"gulp-build": "gulp build" // As does this!!
},
Ahh, that makes sense. I was looking for the relative path to gulp in the project couldn't find the right path. Indeed ./node_modules/.bin/gulp does work. And thank you RobC for quoting that telling line in the docs. Totally makes sense now!

Why does `npm init` Assume NPM Package Build?

This is definitely a theoretical question, but why does running npm init ask a bunch of questions for setting up the fields below?
"name": "my-project-that's-definitely not going to npm",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
A very large percentage of us are using npm just for the package management aspect of it. It seems to me like there should be an option to not set it up as anything BUT a package manager, so just:
"dependencies": {
"#whatever/somepackage": ">=4.0.0-beta <5.0.0",
},
The only justification I can think of is that a lot of people also use npm as a build tool, so this provides an entry point for running scripts. Is that correct? Are there other reasons?
P.S. I know I can use -y flag to default the fields, but that still creates them.
You are correct that npm foremost purpose is a package manager.
And being a package manager, it manages various aspect of a package.
Being a package, it means your code should be able to distribute and reuse by others.
Thus that's why basic information such as name, version, and license are needed.
And npm init is the best place and best time to declare those.
As you mention, you can use npm init -y to use default values so that you don't have to answer them.