问题
I have set up Browser Sync to work with nodemon and express. I am not using gulp or grunt, but rather running everything through npm scripts in my package.json file.
Now, everything works, but I get an error when running my scripts and would like to know what the error is about and how I can fix it.
First, here is my setup:
{
"scripts": {
"dev": "npm run development",
"dev:css": "postcss assets/css/style.css -o public/assets/css/style.css",
"dev:sync": "browser-sync start --proxy 'localhost:3000' --files='./views/**/*.html' --no-ui --no-notify",
"development": "cross-env NODE_ENV=development concurrently \"npm:dev:css\" \"nodemon app.js -e js,html\" \"npm:dev:sync\"",
},
"dependencies": {
"concurrently": "^5.2.0",
"express": "^4.17.1"
},
"devDependencies": {
"browser-sync": "^2.26.10",
"cross-env": "^7.0.2"
}
}
And here is the error message:
YError: Invalid first argument. Expected boolean or string but received function.
[dev:sync] at argumentTypeError (C:\laragon\www\projects\startup-reporter--node\node_modules\yargs\build\lib\argsert.js:64:11)
[dev:sync] at C:\laragon\www\projects\startup-reporter--node\node_modules\yargs\build\lib\argsert.js:45:17
[dev:sync] at Array.forEach (<anonymous>)
[dev:sync] at Object.argsert (C:\laragon\www\projects\startup-reporter--node\node_modules\yargs\build\lib\argsert.js:38:25)
[dev:sync] at Object.version (C:\laragon\www\projects\startup-reporter--node\node_modules\yargs\build\lib\yargs.js:796:19)
[dev:sync] at runFromCli (C:\laragon\www\projects\startup-reporter--node\node_modules\browser-sync\dist\bin.js:46:10)
[dev:sync] at Object.<anonymous> (C:\laragon\www\projects\startup-reporter--node\node_modules\browser-sync\dist\bin.js:38:5)
[dev:sync] at Module._compile (internal/modules/cjs/loader.js:776:30)
[dev:sync] at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
[dev:sync] at Module.load (internal/modules/cjs/loader.js:643:32)
Any idea what this message is about and how I can fix it?
Thanks.
回答1:
There was an issue opened in the repo here: https://github.com/BrowserSync/browser-sync/issues/1782
Looks like a downgrade might be a workaround until the team addresses the issue. npm -g install browser-sync@2.26.7
. I just confirmed this does remove the warning.
Also noted there that this is not an error, but a warning, so the package will work as expected, but console output will be muddied.
回答2:
I installed browser-sync, via sudo npm install -g browser-sync
on my linux machine and i get the exact same error.
Node version:
~$ node -v
v10.13.0
Npm version:
~$ npm -v
6.4.1
Then i run browser-sync --version
to get:
YError: Invalid first argument. Expected boolean or string but received function.
at argumentTypeError (/usr/local/lib/node_modules/browser-sync/node_modules/yargs/build/lib/argsert.js:64:11)
at parsed.optional.forEach (/usr/local/lib/node_modules/browser-sync/node_modules/yargs/build/lib/argsert.js:45:17)
at Array.forEach (<anonymous>)
at Object.argsert (/usr/local/lib/node_modules/browser-sync/node_modules/yargs/build/lib/argsert.js:38:25)
at Object.version (/usr/local/lib/node_modules/browser-sync/node_modules/yargs/build/lib/yargs.js:796:19)
at runFromCli (/usr/local/lib/node_modules/browser-sync/dist/bin.js:46:10)
at Object.<anonymous> (/usr/local/lib/node_modules/browser-sync/dist/bin.js:38:5)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
[Function]
Although i am beginner with npm, it does not seem to be a permissions issue
回答3:
I'm having the same error on windows, I tried as per documentation installing visual studio to fix some c+ problem and reinstalled and it keeps appearing the same error, when I install globally it works'ish but if I install on a single project it does not even recognize browser-sync version prompt, I tried updating npm and node, and the problem remain, but I notice that when I install things like node-sass I'm having the same issue which were not there before, so I'm guessing the problem has to do with some global configuration of npm, I reinstalled it and still nothing, so something else must be conflicting it, today I was gonna try yarn, and see what happens.
what do you get when you prompt npm list --depth 0
https://gist.github.com/soyrbto/5bc81049780baab3f3c4211c0b7548bd
this is happening to me, I want to check that we have the same problem
回答4:
I found the answer, I uninstall node from the ground using this How to completely remove node.js from Windows and reinstalled it (if you want to install additional components as chocolatey you have to have installed visual studio 2017 if not you will see an error)
after I reinstalled it I managed to install and get working the packages again, it seems that it was a conflict that does not disappear unless you remove the folders manually.
Also I install the latest version of node, I dont believe this has nothing to do with it but in case you want replicate exactly what I did.
来源:https://stackoverflow.com/questions/62981085/error-when-running-browsersync-from-package-json-scripts