npm error E401: Unable to authenticate, need: Basic realm="GitHub" - github

I have an issue with node v10.15.1 and npm v6.14.15
Running npm install into the root folder of a project, I have the following error:
npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="GitHub"
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/myuser/.npm/_logs/2022-08-10T17_31_09_840Z-debug.log
The log file reports this:
2675 verbose stack Error: Unable to authenticate, need: Basic realm="GitHub"
2675 verbose stack at res.buffer.catch.then.body (/Users/myuser/.nvm/versions/node/v10.15.1/lib/node_modules/npm/node_modules/npm-registry-fetch/check-response.js:107:17)
2675 verbose stack at process._tickCallback (internal/process/next_tick.js:68:7)
2676 verbose statusCode 401
2677 verbose pkgid socket.io-client#https://github.com/substack/socket.io-client/tarball/master
2678 verbose cwd /Users/myuser/myproject
2679 verbose Darwin 20.6.0
2680 verbose argv "/Users/myuser/.nvm/versions/node/v10.15.1/bin/node" "/Users/myuser/.nvm/versions/node/v10.15.1/bin/npm" "install"
2681 verbose node v10.15.1
2682 verbose npm v6.14.15
2683 error code E401
2684 error Unable to authenticate, need: Basic realm="GitHub"
2685 verbose exit [ 1, true ]
I have other projects that compile perfectly with node v10.15.1 and npm v6.14.15
Any help will be appreciated.
Thanks

I solved this problem by myself.
If you have a similar issue, check in your npm configurations if you have the option always-auth=true, typing:
npm config list
In my case, I had :
; userconfig /Users/myuser/.npmrc
always-auth = true
In order to bypass this problem, create a .npmrc file in the root folder of your project and force the property to false:
always-auth = false
Now, npm config list should show you something like this:
; project config /Users/myuser/myproject/.npmrc
always-auth = false
With this configuration you should solve the E401 Basic realm="GitHub"

Related

TypeError: JwtStrategy requires a secret or key

I've read the million threads with the same issue but I couldn't solve it :(
This is an old project I made and I need to access to it again but I'm getting the following error when running npm start:
> express-typescript-starter#0.1.0 start
> npm run tsc && npm run serve
> express-typescript-starter#0.1.0 tsc
> tsc
> express-typescript-starter#0.1.0 serve
> ts-node src/server.ts
{"level":"debug","message":"Logging initialized at debug level"}
C:\Users\alan_\Desktop\cdng\mern-finance-server-master\node_modules\passport-jwt\lib\strategy.js:45
throw new TypeError('JwtStrategy requires a secret or key');
^
TypeError: JwtStrategy requires a secret or key
at new JwtStrategy (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\node_modules\passport-jwt\lib\strategy.js:45:15)
at Object.<anonymous> (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\src\config\passport.ts:6:28)
at Module._compile (node:internal/modules/cjs/loader:1149:14)
at Module.m._compile (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\node_modules\ts-node\src\index.ts:858:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1203:10)
at Object.require.extensions.<computed> [as .ts] (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\node_modules\ts-node\src\index.ts:861:12)
at Module.load (node:internal/modules/cjs/loader:1027:32)
at Function.Module._load (node:internal/modules/cjs/loader:868:12)
at Module.require (node:internal/modules/cjs/loader:1051:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\src\app.ts:16:1)
at Module._compile (node:internal/modules/cjs/loader:1149:14)
at Module.m._compile (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\node_modules\ts-node\src\index.ts:858:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1203:10)
at Object.require.extensions.<computed> [as .ts] (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\node_modules\ts-node\src\index.ts:861:12)
at Module.load (node:internal/modules/cjs/loader:1027:32)
This is src/config/passport.ts:
import passport from 'passport'
import { Strategy as JwtStrategy, ExtractJwt } from 'passport-jwt'
import userServices from '../services/userServices'
import { JWT_SECRET } from '../util/secret'
export const jwtStrategy = new JwtStrategy(
{
secretOrKey: JWT_SECRET,
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
},
async (payload: any, done: any) => {
const userEmail = payload.email
const foundUser = await userServices.findUserByEmail(userEmail)
done(null, foundUser)
}
)
When running "npm i" I'm getting a bunch of errors as well but I could --force it:
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: jest-config#27.5.1
npm WARN Found: ts-node#8.10.2
npm WARN node_modules/ts-node
npm WARN dev ts-node#"^8.6.2" from the root project
npm WARN
npm WARN Could not resolve dependency:
npm WARN peerOptional ts-node#">=9.0.0" from jest-config#27.5.1
npm WARN node_modules/jest-config
npm WARN jest-config#"^27.5.1" from #jest/core#27.5.1
npm WARN node_modules/#jest/core
npm WARN 1 more (jest-cli)
npm WARN
npm WARN Conflicting peer dependency: ts-node#10.9.1
npm WARN node_modules/ts-node
npm WARN peerOptional ts-node#">=9.0.0" from jest-config#27.5.1
npm WARN node_modules/jest-config
npm WARN jest-config#"^27.5.1" from #jest/core#27.5.1
npm WARN node_modules/#jest/core
npm WARN 1 more (jest-cli)
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: ts-jest#26.5.6
npm ERR! Found: jest#27.5.1
npm ERR! node_modules/jest
npm ERR! dev jest#"^27.5.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer jest#">=26 <27" from ts-jest#26.5.6
npm ERR! node_modules/ts-jest
npm ERR! dev ts-jest#"^26.5.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: jest#26.6.3
npm ERR! node_modules/jest
npm ERR! peer jest#">=26 <27" from ts-jest#26.5.6
npm ERR! node_modules/ts-jest
npm ERR! dev ts-jest#"^26.5.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
You can see the whole repo here.
Thanks!
I'm not going to attempt to fix your conflicts, but npm i -force will allow everything to be installed.
You will also need to place a .env file in the root and ensure it has a JWT_SECRET secret value.
There are also a lot of other .env values required. Your .env should look like this (or production):
JWT_SECRET = 'jhagdhjwf'
MONGODB_URI = 'mongodb://localhost:27017/local'
PORT = 3000
CLOUD_NAME = 'Your cloud name'
CLOUDINARY_API_KEY = '123123123123'
CLOUDINARY_API_SECRET = 'abc123abc123abc123abc123'
NODE_ENV = 'production'
I don't know why you didn't think an .env was not required. I thought you said this was your project?
As you will also know, you have to have cloudinary API config and also a running mongodb server, on which you store your data.
Eg, install docker and run the command to get a quick running local version:
docker run -d -p 27017:27017 --name test-mongo mongo:latest
I did a pull of the code and everything works locally. Add this .env and it will work:
> express-typescript-starter#0.1.0 start
> npm run tsc && npm run serve
> express-typescript-starter#0.1.0 tsc
> tsc
> express-typescript-starter#0.1.0 serve
> ts-node src/server.ts
{"level":"debug","message":"Logging initialized at debug level"}
(node:78699) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
App running on port 3000
Opening http://localhost:3000/api/v1/users will give you the expected [] response. I assume you have a front end somewhere.
Everything should be working as expected.
Extra: Your import { JWT_SECRET } from '../util/secret' is not the right file name. In your repo it is https://github.com/AlanFPS/mern-finance-server/blob/master/src/util/seccret.ts. Your import is looking for secret but your file is called seccret (two c's).

Fix error permission denied "/Users/name/Library/Application Support/Lens/node_modules/lenscloud-lens-extension" while open lens apps

How to fix pop up error permission denied?
The log:
50 silly saveTree +-- lens-survey#5.2.5-latest.20211001.2
50 silly saveTree +-- lens-telemetry#5.2.5-latest.20211001.2
50 silly saveTree `-- lenscloud-lens-extension#5.2.5-latest.20211001.2
51 warn Lens No description
52 warn Lens No repository field.
53 warn Lens No license field.
54 verbose stack Error: EACCES: permission denied, access '/Users/162408.suryadi/Library/Application Support/Lens/node_modules/lenscloud-lens-extension'
55 verbose cwd /Users/162408.suryadi/Library/Application Support/Lens
56 verbose Darwin 20.4.0
57 verbose argv "/Applications/Lens.app/Contents/Frameworks/Lens Helper.app/Contents/MacOS/Lens Helper" "/Applications/Lens.app/Contents/Resources/app.asar/node_modules/npm/bin/npm-cli.js" "install" "--no-audit" "--only=prod" "--prefer-offline" "--no-package-lock"
58 verbose node v14.16.0
59 verbose npm v6.14.13
60 error code EACCES
61 error syscall access
62 error path /Users/162408.suryadi/Library/Application Support/Lens/node_modules/lenscloud-lens-extension
63 error errno -13
64 error Error: EACCES: permission denied, access '/Users/162408.suryadi/Library/Application Support/Lens/node_modules/lenscloud-lens-extension'
64 error [Error: EACCES: permission denied, access '/Users/162408.suryadi/Library/Application Support/Lens/node_modules/lenscloud-lens-extension'] {
64 error errno: -13,
64 error code: 'EACCES',
Could not load extensions: npm WARN checkPermissions Missing write access to /Users/162408.suryadi/Library/Application Support/Lens/node_modules/lenscloud-lens-extension
npm WARN enoent ENOENT: no such file or directory, open '/Users/162408.suryadi/Library/Application Support/Lens/node_modules/untitled folder/package.json'
npm WARN Lens No description
npm WARN Lens No repository field.
npm WARN Lens No license field.
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /Users/162408.suryadi/Library/Application Support/Lens/node_modules/lenscloud-lens-extension
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/Users/162408.suryadi/Library/Application Support/Lens/node_modules/lenscloud-lens-extension'
npm ERR! [Error: EACCES: permission denied, access '/Users/162408.suryadi/Library/Application Support/Lens/node_modules/lenscloud-lens-extension'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/Users/162408.suryadi/Library/Application Support/Lens/node_modules/lenscloud-lens-extension'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/162408.suryadi/.npm/_logs/2021-10-21T02_16_36_016Z-debug.log
In your logs you can find the description of your problem:
It is likely you do not have the permissions to access this file as the current user.
And one more thing to check:
If you believe this might be a permissions issue, please double-check the permissions of the file and its containing directories, or try running the command again as root/Administrator.
The error you got is because you cannot access the resource /Users/162408.suryadi/Library/Application Support/Lens/node_modules/lenscloud-lens-extension from the current user. If you want to fix it, you have to change the permissions for this resource or change its owner. It is also possible (since you are using Kubernetes) that you will have to make such a change in the image of the system you are using.
To change owner the resource run
sudo chown -R $USER /Users/162408.suryadi/Library/Application Support/Lens/node_modules/lenscloud-lens-extension
You can find also many similar problems. In most cases, the only difference will be the different path to the resource. The mode of operation and the solution to the problem remains the same:
Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
https://progressivecoder.com/how-to-easily-fix-missing-write-access-error-npm-install/
https://flaviocopes.com/npm-fix-missing-write-access-error/

AssertionError [ERR_ASSERTION]: Host should not be empty at proxy in expressjs

i am trying to run expressjs project it's shows errors like
AssertionError [ERR_ASSERTION]: Host should not be empty at proxy (/../../Desktop/folder/myproject/node_modules/express-http-proxy/index.js:27:3)
{
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: undefined,
expected: true,
operator: '=='
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! authentication#1.0.0 start: ./node_modules/typescript/bin/tsc; node main
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the authentication#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/folder/.npm/_logs/2020-01-01T07_03_08_044Z-debug.log
Your app is using proxy from express-http-proxy, proxy is supposed to take first argument as a value. That value is missing or undefined.
Check all the occurrence of proxy function inside your app and find the missing argument, most probably you have defined that value and taken from .env file but it's not define inside .env file.

Running SASS on Gatsby not working

Yesterday, I was able to setup a starter-pack instance of gatsby and deploy to github pages.
Since then, I've updated my react/js files locally, which seemed to run fine locally. Now I want to compile my sass:
I can't find a decent solution which works:
Here's the sass compiler I tried to install:
sass --watch assets/scss/main.scss:assets/css/style.css
Node sass watch runs, but doesn't actually compile anything. I get an error instead:
Problems:
1) Since installing the sass
./src/assets/scss/main.scss
Module parse failed: /Users/reenaverma/development/GATSBY/src/assets/scss/main.scss Unexpected character '#' (1:8)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '#' (1:8)
at Parser.pp$4.raise (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp$7.getTokenFromCode (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:2756:10)
at Parser.pp$7.readToken (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:2477:17)
at Parser.pp$7.nextToken (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:2468:15)
at Parser.pp$7.next (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:2413:10)
at Parser.pp.eat (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:536:12)
at Parser.pp$1.parseStatement (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:728:71)
at Parser.pp$1.parseTopLevel (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:638:25)
at Parser.parse (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:516:17)
at Object.parse (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:3098:39)
at Parser.parse (/Users/reenaverma/development/GATSBY/node_modules/webpack/lib/Parser.js:902:15)
at NormalModule.<anonymous> (/Users/reenaverma/development/GATSBY/node_modules/webpack/lib/NormalModule.js:104:16)
at NormalModule.onModuleBuild (/Users/reenaverma/development/GATSBY/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
at nextLoader (/Users/reenaverma/development/GATSBY/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
at /Users/reenaverma/development/GATSBY/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
at Storage.finished (/Users/reenaverma/development/GATSBY/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
at /Users/reenaverma/development/GATSBY/node_modules/graceful-fs/graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:528:3)
# ./src/layouts/index.js 29:0-35
2) I've even tried this link, but this doesn't work either:
https://www.npmjs.com/package/gatsby-plugin-sass
3) For some reason, I also can't deploy to Github/git push origin master / npm run deploy
error: ./src/assets/scss/main.scss
Module parse failed: /Users/reenaverma/development/GATSBY/src/assets/scss/main.scss Unexpected character '#' (1:8)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '#' (1:8)
at Parser.pp$4.raise (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp$7.getTokenFromCode (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:2756:10)
at Parser.pp$7.readToken (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:2477:17)
at Parser.pp$7.nextToken (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:2468:15)
at Parser.pp$7.next (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:2413:10)
at Parser.pp.eat (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:536:12)
at Parser.pp$1.parseStatement (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:728:71)
at Parser.pp$1.parseTopLevel (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:638:25)
at Parser.parse (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:516:17)
at Object.parse (/Users/reenaverma/development/GATSBY/node_modules/acorn/dist/acorn.js:3098:39)
at Parser.parse (/Users/reenaverma/development/GATSBY/node_modules/webpack/lib/Parser.js:902:15)
at NormalModule.<anonymous> (/Users/reenaverma/development/GATSBY/node_modules/webpack/lib/NormalModule.js:104:16)
at NormalModule.onModuleBuild (/Users/reenaverma/development/GATSBY/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
at nextLoader (/Users/reenaverma/development/GATSBY/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
at /Users/reenaverma/development/GATSBY/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
at Storage.finished (/Users/reenaverma/development/GATSBY/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
# ./src/layouts/index.js 28:0-35
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gatsby-starter-default#1.0.0 deploy: `gatsby build --prefix-paths && gh-pages -b master -d public`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gatsby-starter-default#1.0.0 deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/reenaverma/.npm/_logs/2018-05-30T13_34_31_289Z-debug.log
PLEASE HELP! I need this sorted by tonight:
Here's my code from yesterday.... But I have updated 3 js files. But this works locally. Seems trying to run sass is breaking my work:
https://github.com/ReenaVerma/reenaverma.github.io/tree/master
The following 2 steps has helped me:
1) run npm install gatsby-plugin-sass to download sass plugin for Gatsby;
2) add gatsby-plugin-sass to plugins section of the gatsby-config.json file.

cannot read property 'access_token" of undefined

I'm using Auth0 and trying to get AccessToken. But I faced to difficult problem.
how can I solve this problem?
I've got an error like this:
E:\sample projects\Building-API\movieanalyst-website\server.js:27
if(req.body.access_token){
^
TypeError: Cannot read property 'access_token' of undefined
at E:\sample projects\Building-API\movieanalyst-website\server.js:27:18
at Request.callback (E:\sample projects\Building-API\movieanalyst-website\node_modules\superagent\lib\node\index.js:688:3)
at E:\sample projects\Building-API\movieanalyst-website\node_modules\superagent\lib\node\index.js:883:18
at IncomingMessage.<anonymous> (E:\sample projects\Building-API\movieanalyst-website\node_modules\superagent\lib\node\parsers\json.js:16:7)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
npm ERR! Windows_NT 10.0.10240
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v7.9.0
npm ERR! npm v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! movieanalyst-website#1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the movieanalyst-website#1.0.0 start script 'node server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the movieanalyst-website package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs movieanalyst-website
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls movieanalyst-website
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Assassin\AppData\Roaming\npm-cache\_logs\2017-07-24T11_28_24_478Z-debug.log
According to the error, code is this
function getAccessToken(req, res, next) {
request
.post('https://shinji-sakai.auth0.com/oauth/token')
.send(authData)
.end(function(err, res) {
if(req.body.access_token){
req.access_token = res.body.access_token;
next();
} else {
res.send(401, 'Unauthorized');
}
})
}
plz, give me the way to solve this problem.
Thanks :)
It seems that the body property from your req request is undefined. You should check you request to see if you are sending the correct data. Maybe you can use postman or another RESTful API to test.
Also you can change your code to check the body property first, like this (but I think that your problem is with the actual request):
function getAccessToken(req, res, next) {
request
.post('https://shinji-sakai.auth0.com/oauth/token')
.send(authData)
.end(function(err, res) {
if(req.body && req.body.access_token) {
req.access_token = res.body.access_token;
next();
} else {
res.send(401, 'Unauthorized');
}
})
}