Pre-Commit Error 'Cannot Find Module - npx-cli.js' When Using Husky - pre-commit-hook

I am trying to run a pre-commit hook that checks check my style using husky and stylelint but when I try to commit a file GitKracken fails. The log reads as follows:
Error: Cannot find module C:\Users\name\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
at Function.Module._load (internal/modules/cjs/loader.js:686:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT FOUND',
requireStack: []
}
I am running npm version: 6.13.4 and node version: 12.14.1. From my research npx is installed with npm in any versions over 5 or so already. I've also tried globally installing npx as well but it fails to install claiming file already exists.
I am sure it is a path problem or perhaps I am using husky incorrectly but figured I'd reach to to see if anyone knows why I'm having issues getting this to work. Thanks for any insights you may have.
package.json
// I've tested rand the stylelint command manually and it does check for stylelint errors
{
"husky": {
"hooks": {
"pre-commit": "node ./node_modules/stylelint/bin/stylelint.js ./src/scss/**/*.scss"
}
}
}

You have very likely updated Husky from v4 to v7, look at migration guide.

Related

generating new nestjs module results in Error: Failed to execute command

I'm using MacOS monterey with M1 chip as my operating system. installed NestJS cli using this command: sudo npm install -g #nestjs/cli
when creating new nest project using nest new message everything works fine, but when I try to create new module using this command nest generate module messages I face error.
why does this happen? I tried installing schematics using npm i -g #nestjs/schematics, I don't know if I should've installed it but this didn't help anyway.
The error I face is:
/Users/homayoun/training/messages/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:338
throw new Error(`Unknown argument ${key}. Did you mean ${(0, yargs_parser_1.decamelize)(key)}?`);
^
Error: Unknown argument skipImport. Did you mean skip-import?
at parseArgs (/Users/homayoun/training/messages/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:338:19)
at main (/Users/homayoun/training/messages/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:122:49)
at Object.<anonymous> (/Users/homayoun/training/messages/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:367:5)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
Failed to execute command: node #nestjs/schematics:module --name=messages --no-dry-run --no-skipImport --language="ts" --sourceRoot="src" --spec.
worth noting that I don't face any issues when I do the same thing on ubuntu 20 or 22
Quick solution:
add this to your nest-cli.json
"root": "src"
change into the src of your project folder
cd src
run
nest generate module messages
if the above does not work also try changing the version of packages in package.json to
"#nestjs/cli": "8.2.6",
"#nestjs/schematics": "8.0.11",
removing the node modules in the current project
reinstalling the nest cli with
npm uninstall -g #nestjs/cli
npm i -g #nestjs/cli#8.2.6
this is a bug on the latest version of #nestjs/cli (v8.2.7). Downgrade it to 8.2.6 and it will work (I tested it). It was reported here: https://github.com/nestjs/nest-cli/issues/1693
Also, I don't recommend using the global version of the CLI. Instead, use npx nest or yarn nest.

errorr in node:internal/modules/cjs/loader:488

I'm trying to run react app I got this error:
☁ app [master] yarn start
yarn run v1.22.17
$ react-scripts start
node:internal/modules/cjs/loader:488
throw e;
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/tokenize' is not defined by "exports" in /Users/li/Documents/reacts/app/node_modules/postcss-safe-parser/node_modules/postcss/package.json
at new NodeError (node:internal/errors:371:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:416:9)
at packageExportsResolve (node:internal/modules/esm/resolve:669:3)
at resolveExports (node:internal/modules/cjs/loader:482:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/li/Documents/reacts/app/node_modules/postcss-safe-parser/lib/safe-parser.js:1:17) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
Node.js v17.0.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
How do I download the app ?
npx create-react-app my-app
cd my-app
npm start
my stuff version
node -v v17.0.1
yarn -v 1.22.17
npm -v 8.1.4
I've tried every single thing in this but nothing worked for me
I was also getting this error, then I ran npm update and that seemed to clear up this error. But now I'm getting a new error about "no such file or directory, stat '/home//.steampath'"
Maybe that's just a separate issue with mine though, hopefully npm update works for you!
Edit: I was able to fix my "no such directory" error, it was caused by an issue with me trying to transfer a file from a different drive. I was able to resolve it. So unless you also have that same problem, npm update should fix it for you.
I had this issue, as well. I was able to get CRA to work by installing/using Node v16.13.1 via NVM. This is an issue with CRA depending on an old version of postcss-safe-parser referenced here.
First install NVM and then ...
nvm install 16
Make sure node 16 is being used by NVM and yarn start should work.

electron-builder and robotjs rebuild issues

I have an electron project using robotjs. I am trying to build it using electron-builder on OSX catalina 10.15.7, however, I am running into issues when it comes to generating a distribution build. If I switch over to electron-forge, everything works fine, but I really like all the options that I get with electron-builder more (license files, and much more). Here is the error:
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 82. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at process.func [as dlopen] (electron/js2c/asar.js:140:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1196:18)
at Object.func [as .node] (electron/js2c/asar.js:140:31)
at Module.load (internal/modules/cjs/loader.js:981:32)
at Module._load (internal/modules/cjs/loader.js:881:14)
at Function.Module._load (electron/js2c/asar.js:779:28)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/Users/me/Documents/MyElectronApp/node_modules/robotjs/index.js:1:15)
at Module._compile (internal/modules/cjs/loader.js:1145:30)
I have seen other posts where there are instructions to rebuild with robotjs to get around this error, for example this:
1. Run npm i -D electron-rebuild #to add the electron-rebuild package
2. Remove the node-modules folder, as well as the packages-lock.json file.
3. Run npm i to install all modules.
4. Run ./node_modules/.bin/electron-rebuild (.\node_modules\.bin\electron-rebuild.cmd for Windows) to rebuild everything
While this works in dev mode (electron-webpack dev), it does not work when I try to create a distribution. The generated app files when launched fail with the error above as well.
I have tried to change my build scripts to something like this to simulate what I am doing in dev mode, but I did not get any different results. Here are two additional script targets I added:
"dist": "rm -rf node_modules && rm yarn.lock && yarn install && ./node_modules/.bin/electron-rebuild && electron-builder",
"simpledist": "electron-rebuild -o robotjs -v 10.3.1"
Here are my dependancies:
"devDependencies": {
"electron": "10.3.1",
"electron-builder": "^22.9.1",
"electron-rebuild": "^2.3.4",
"electron-webpack": "^2.8.2",
"webpack": "~4.42.1"
},
"dependencies": {
"express": "^4.17.1",
"robotjs": "^0.6.0",
"source-map-support": "^0.5.19",
"winston": "^3.3.3"
}
Does anyone know how I can get electron-builder to build an app with robotjs as a dependency? thank you

npm error - verify that the package.json has a valid "main" entry

Im playing around with a simple trading bot using binance and cctx
when i run my script with node index.js
i get this long error:
internal/modules/cjs/loader.js:323
throw err;
^
Error: Cannot find module '/home/ether/Documents/nodesendeth/node_modules/cctx/index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (internal/modules/cjs/loader.js:315:19)
at Function.Module._findPath (internal/modules/cjs/loader.js:703:18)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:967:27)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1040:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/home/ether/Documents/nodesendeth/index.js:2:14)
at Module._compile (internal/modules/cjs/loader.js:1151:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
at Module.load (internal/modules/cjs/loader.js:1000:32) {
code: 'MODULE_NOT_FOUND',
path: '/home/ether/Documents/nodesendeth/node_modules/cctx/package.json',
requestPath: 'cctx'
}
so it basically cant find the cctx module
cctx was installed with npm i cctx and i also ran npm install afterwards just to make sure.
It also says verify that package.json file has a valid main entry, which it does:
{
"name": "nodesendeth",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"cctx": "^1.0.1",
"dotenv": "^8.2.0"
}
}
I pasted the code to my script here
https://paste.ubuntu.com/p/p4n6MH3vbn/
Also my await functions arent working- even though i use them in an async function
So Im not a 100% sure what exactly the error is, there is a main entry in the package.json file and the cctx module has been installed
For me removing my node_modules folder and running npm i solve the problem
Delete node_modules
Run "npm i"
Fixed
For me, the cause was that I accidentally hit STRG + C while installing all the modules, which broke something.
If you are working with firebase functions, and you are using TypeScript, check the path to the generated index.js after npm run build.
In my case it was lib/functions/src/main.js.
setting:
"main": "lib/functions/src/index.js",
on package.json fixed the issue
https://www.npmjs.com/package/cctx <- Not a valid package. It's a typo for this package: https://www.npmjs.com/package/ccxt (CCXT instead of CCTX). Install that instead. The issue isn't with your code, it's that you installed the wrong package.
If you are working with firebase functions, and you are using TypeScript,
run the
npm run build
inside the Function directory
after that, a folder is generated in the current folder lib
then return back and fire!
$ firebase deploy
Run npm update, it will fix the issue
Or you can also delete node_modules and the package-lock.json file then npm install will also solve the issue.
In my case, I was getting this error from my VS Code ESLint plugin output. However running the linter through the terminal was just fine. After exhausting other options, restarting VS Code did the trick and ESLint plugin runs.
I have also faced the same Problem earlier.
I solved the problem by deleting the nodemodules folder and then
npm update
then
npm install
node:internal/modules/cjs/loader:361 throw err; ^
Error: Cannot find module '/Users/node_modules/express/server.js'. Please verify that the package.json has a valid "main" entry
fixed the above error - by making sure the express.js was added into my package.json as a dependency.
"dependencies": { "ejs": "^3.1.6", "express-ejs": "^2.0.0", "express-ejs-layouts": "^2.5.1", "express.js": "^1.0.0" },
I have faced the same issue once when the packages didn't install properly.
Add fixed this by reinstalling packages after deleting the node_modules folder.
this worked for me :
first uninstall node and go to the installation directory (C:\Program Files\nodejs)
and remove every file and folder there.
reinstall node

Error When Running BrowserSync from Package.json Scripts

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.
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.
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
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
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.

Resources