Kerberos library is not installed - node.js

I have a simple project to test Kerberos authentication. This is a Windows machine.
In my package.json:
"dependencies": {
"kerberos": "^0.0.24",
"mongodb": "^3.0.10"
}
Connection URL:
const url = 'mongodb://userxxx%40XXXXX.XXXXX.COM:Password01#servername:27017/?authMechanism=GSSAPI&authSource=%24external&ssl=true';
But when I'm trying to connect in the code:
MongoClient.connect(url, (err, client) => {
if (err) {
console.error(err);
I get an error message Error: Kerberos library is not installed
I tried nuking node_modules and reinstalling everything. I tried installing kerberos module globally and locally. Same consistent result every time. Looking for insights. Thank you.
EDIT:
No errors during installation/compilation:
$ yarn add mongodb kerberos
yarn add v1.5.1
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 8 new dependencies.
info Direct dependencies
├─ kerberos#0.0.24
└─ mongodb#3.0.10
info All dependencies
├─ bson#1.0.9
├─ kerberos#0.0.24
├─ mongodb-core#3.0.9
├─ mongodb#3.0.10
├─ nan#2.10.0
├─ require_optional#1.0.1
├─ resolve-from#2.0.0
└─ semver#5.5.0
Done in 23.56s.
EDIT 2:
C:\Users\username\Projects\node.js\kerberos-test>npm init -y
Wrote to C:\Users\username\Projects\node.js\kerberos-test\package.json:
{
"name": "kerberos-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
C:\Users\username\Projects\node.js\kerberos-test>npm install kerberos mongodb
--save
> kerberos#0.0.24 install C:\Users\username\Projects\node.js\kerberos-test\nod
e_modules\kerberos
> (node-gyp rebuild) || (exit 0)
C:\Users\username\Projects\node.js\kerberos-test\node_modules\kerberos>if not
defined npm_config_node_gyp (node "C:\Users\username\AppData\Roaming\npm\node_
modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp
\bin\node-gyp.js" rebuild ) else (node "C:\Users\username\AppData\Roaming\npm
\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
kerberos.cc
worker.cc
security_buffer.cc
security_buffer_descriptor.cc
security_context.cc
security_credentials.cc
win_delay_load_hook.cc
..\lib\win32\wrappers\security_credentials.cc(314): warning C4996: 'Nan::Callba
ck::Call': was declared deprecated [C:\Users\username\Projects\node.js\kerber
os-test\node_modules\kerberos\build\kerberos.vcxproj]
C:\Users\username\Projects\node.js\kerberos-test\node_modules\nan\nan.h(161
8): note: see declaration of 'Nan::Callback::Call'
..\lib\win32\wrappers\security_credentials.cc(341): warning C4996: 'Nan::Callba
ck::Call': was declared deprecated [C:\Users\username\Projects\node.js\kerber
os-test\node_modules\kerberos\build\kerberos.vcxproj]
C:\Users\username\Projects\node.js\kerberos-test\node_modules\nan\nan.h(161
8): note: see declaration of 'Nan::Callback::Call'
..\lib\win32\wrappers\security_context.cc(49): warning C4996: 'Nan::Callback::C
all': was declared deprecated [C:\Users\username\Projects\node.js\kerberos-te
st\node_modules\kerberos\build\kerberos.vcxproj]
C:\Users\username\Projects\node.js\kerberos-test\node_modules\nan\nan.h(161
8): note: see declaration of 'Nan::Callback::Call'
..\lib\win32\wrappers\security_context.cc(67): warning C4996: 'Nan::Callback::C
all': was declared deprecated [C:\Users\username\Projects\node.js\kerberos-te
st\node_modules\kerberos\build\kerberos.vcxproj]
C:\Users\username\Projects\node.js\kerberos-test\node_modules\nan\nan.h(161
8): note: see declaration of 'Nan::Callback::Call'
..\lib\win32\wrappers\security_context.cc(612): warning C4311: 'type cast': poi
nter truncation from 'unsigned long *' to 'unsigned long' [C:\Users\username\
Projects\node.js\kerberos-test\node_modules\kerberos\build\kerberos.vcxproj]
..\lib\win32\wrappers\security_context.cc(612): warning C4302: 'type cast': tru
ncation from 'unsigned long *' to 'unsigned long' [C:\Users\username\Projects
\node.js\kerberos-test\node_modules\kerberos\build\kerberos.vcxproj]
base64.c
kerberos_sspi.c
Creating library C:\Users\username\Projects\node.js\kerberos-test\node_m
odules\kerberos\build\Release\kerberos.lib and object C:\Users\username\Pro
jects\node.js\kerberos-test\node_modules\kerberos\build\Release\kerberos.exp
Generating code
Finished generating code
kerberos.vcxproj -> C:\Users\username\Projects\node.js\kerberos-test\node_m
odules\kerberos\build\Release\\kerberos.node
kerberos.vcxproj -> C:\Users\username\Projects\node.js\kerberos-test\node_m
odules\kerberos\build\Release\kerberos.pdb (Full PDB)
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN kerberos-test#1.0.0 No description
npm WARN kerberos-test#1.0.0 No repository field.
+ kerberos#0.0.24
+ mongodb#3.0.10
added 8 packages from 13 contributors and audited 8 packages in 22.648s
found 0 vulnerabilities
C:\Users\username\Projects\node.js\kerberos-test>
After copying the index.js file in from the other test project:
C:\Users\username\Projects\node.js\kerberos-test>node index.js
Error: Kerberos library is not installed
at SSPI.auth (C:\Users\username\Projects\node.js\kerberos-test\node_module
s\mongodb-core\lib\auth\sspi.js:58:41)
at authenticate (C:\Users\username\Projects\node.js\kerberos-test\node_mod
ules\mongodb-core\lib\connection\pool.js:244:17)
at authenticateLiveConnections (C:\Users\username\Projects\node.js\kerbero
s-test\node_modules\mongodb-core\lib\connection\pool.js:831:7)
at C:\Users\username\Projects\node.js\kerberos-test\node_modules\mongodb-c
ore\lib\connection\pool.js:876:5
at waitForLogout (C:\Users\username\Projects\node.js\kerberos-test\node_mo
dules\mongodb-core\lib\connection\pool.js:867:34)
at Pool.auth (C:\Users\username\Projects\node.js\kerberos-test\node_module
s\mongodb-core\lib\connection\pool.js:874:3)
at Server.auth (C:\Users\username\Projects\node.js\kerberos-test\node_modu
les\mongodb-core\lib\topologies\server.js:922:20)
at Server.auth (C:\Users\username\Projects\node.js\kerberos-test\node_modu
les\mongodb\lib\topologies\topology_base.js:379:30)
at authenticate (C:\Users\username\Projects\node.js\kerberos-test\node_mod
ules\mongodb\lib\authenticate.js:56:23)
at module.exports (C:\Users\username\Projects\node.js\kerberos-test\node_m
odules\mongodb\lib\authenticate.js:112:12)
C:\Users\username\Projects\node.js\kerberos-test>

After some digging around I found this in mongodb-core/lib/auth/sspi.js:
try {
Kerberos = require_optional('kerberos').Kerberos;
// Authentication process for Mongo
MongoAuthProcess = require_optional('kerberos').processes.MongoAuthProcess;
} catch (err) {} // eslint-disable-line
The problem is it silently catches the error and doesn't report anything. After placing console.log(err) in the catch, I saw the following error:
Error: optional dependency [kerberos] found but version [0.0.24] did not satisfy constraint [^0.0.23]
sspi.js:34
code:"OPTIONAL_MODULE_NOT_FOUND"
message:"optional dependency [kerberos] found but version [0.0.24] did not satisfy constraint [^0.0.23]"
stack:"Error: optional dependency [kerberos] found but version [0.0.24] did not satisfy constraint [^0.0.23]\n at require_optional (c:\Users\apolkousky\Projects\node.js\kerberos-test\node_modules\require_optional\index.js:109:19)\n at Object.<anonymous> (c:\Users\apolkousky\Projects\node.js\kerberos-test\node_modules\mongodb-core\lib\auth\sspi.js:29:14)\n at Module._compile (module.js:643:30)\n at Object.Module._extensions..js (module.js:654:10)\n at Module.load (module.js:556:32)\n at tryModuleLoad (module.js:499:12)\n at Function.Module._load (module.js:491:3)\n at Module.require (module.js:587:17)\n at require (internal/module.js:11:18)\n at Object.<anonymous> (c:\Users\apolkousky\Projects\node.js\kerberos-test\node_modules\mongodb-core\lib\connection\pool.js:25:10)"
__proto__:Object {constructor: , name: "Error", message: "", …}
Downgrading kerberos to version 0.0.23 solved the issue.

Related

rollup plugin "#rollup/plugin-commonjs" parsing package.json and throwing unexpected token error

TL;DR: Why is #rollup/plugin-commonjs looking in my package.json and how can I stop that so that I don't have to include #rollup/plugin-json arbitrarily to fix the problem?
I have a file written in JS for Node.js, CommonJS require() / module.exports() that I want to work in the Browser, so I am using Rollup to bundle and 'browserify' the Node.js code.
Environment
macOS Monterey Version 12.4
npm version 8.3.1
node version 16.14.0
rollup version 2.75.6
#rollup/plugin-json version 4.1.0
rollup.config.js
Here is my rollup.config.js:
// rollup.config.js
import commonjs from '#rollup/plugin-commonjs';
// import json from '#rollup/plugin-json';
const devMode = (process.env.NODE_ENV === 'development');
console.log(`${ devMode ? 'development' : 'production' } mode bundle`);
export default [
{
input: "test/_client_test.js",
output: {
file: 'build/test/test.js',
format: 'iife'
},
plugins: [
commonjs()
]
}
];
Problem
When running npm rollup -c I get the following output:
[!] (plugin commonjs--resolver) Error: Unexpected token (Note that you need #rollup/plugin-json to import JSON files)
package.json (2:8)
1: {
2: "name": "my-package",
^
3: "version": "0.0.1",
4: "description": "hello world",
Error: Unexpected token (Note that you need #rollup/plugin-json to import JSON files)
at error (/***/node_modules/rollup/dist/shared/rollup.js:198:30)
at Module.error (/***/node_modules/rollup/dist/shared/rollup.js:12553:16)
at Module.tryParse (/***/node_modules/rollup/dist/shared/rollup.js:12930:25)
at Module.setSource (/***/node_modules/rollup/dist/shared/rollup.js:12835:24)
at ModuleLoader.addModuleSource (/***********/rollup.js:22309:20)

Resolve deprecation warning "DeprecationWarning: Compilation.cache was removed in favor of Compilation.getCache()"

I use the npm package service-worker-loader. I get this waring when building the project:
node:25260) [DEP_WEBPACK_COMPILATION_CACHE] DeprecationWarning: Compilation.cache was removed in favor of Compilation.getCache()
I have discovered through using:
node --trace-deprecation node_modules/webpack/bin/webpack.js --mode=development
That the problem is in the following code:
onCompilerHook(compiler, 'compilation', compilation => {
if (compilation.cache) {
if (!compilation.cache[subCache]) {
compilation.cache[subCache] = {};
}
compilation.cache = compilation.cache[subCache];
}
});
I am using the latest version (4.0.2) of the package.
Was that deprecation fixed? Is there any possible fix?

Nuxt installation error : Rule can only have one resource source (provided resource and test + include + exclude)

I successfully installed Vuejs and Nodejs but got a problem when installing Nuxtjs. This is what I get. I already asked some friends but it didn't work. Thanks for your help ! :)
Error : Rule can only have one resource source (provided resource and test + include + exclude)
Rule can only have one resource source (provided resource and test + include + exclude) in {
"use": [
{
"loader": "C:\\Users\\User\\Desktop\\JS\\my-first-project\\node_modules\\babel-loader\\lib\\index.js",
"options": {
"configFile": false,
"babelrc": false,
"cacheDirectory": true,
"envName": "server",
"presets": [
[
"C:\\Users\\User\\Desktop\\JS\\my-first-project\\node_modules\\#nuxt\\babel-preset-app\\src\\index.js",
{
"corejs": {
"version": 3
}
}
]
]
},
"ident": "clonedRuleSet-30[0].rules[0].use[0]"
}
]
}
"use": [
{
"loader": "C:\\Users\\User\\Desktop\\JS\\my-first-project\\node_modules\\babel-loader\\lib\\index.js",
"options": {
"configFile": false,
"babelrc": false,
"cacheDirectory": true,
"envName": "server",
"presets": [
[
"C:\\Users\\User\\Desktop\\JS\\my-first-project\\node_modules\\#nuxt\\babel-preset-app\\src\\index.js",
{
"corejs": {
"version": 3
}
}
]
]
},
"ident": "clonedRuleSet-30[0].rules[0].use[0]"
}
]
}
at checkResourceSource (node_modules\#nuxt\webpack\node_modules\webpack\lib\RuleSet.js:167:11)
at Function.normalizeRule (node_modules\#nuxt\webpack\node_modules\webpack\lib\RuleSet.js:198:4)
at node_modules\#nuxt\webpack\node_modules\webpack\lib\RuleSet.js:110:20
at Array.map (<anonymous>)
at Function.normalizeRules (node_modules\#nuxt\webpack\node_modules\webpack\lib\RuleSet.js:109:17)
at new RuleSet (node_modules\#nuxt\webpack\node_modules\webpack\lib\RuleSet.js:104:24)
at new NormalModuleFactory (node_modules\#nuxt\webpack\node_modules\webpack\lib\NormalModuleFactory.js:115:18)
at Compiler.createNormalModuleFactory (node_modules\#nuxt\webpack\node_modules\webpack\lib\Compiler.js:636:31)
at Compiler.newCompilationParams (node_modules\#nuxt\webpack\node_modules\webpack\lib\Compiler.js:653:30)
at Compiler.compile (node_modules\#nuxt\webpack\node_modules\webpack\lib\Compiler.js:661:23)
at node_modules\#nuxt\webpack\node_modules\webpack\lib\Watching.js:77:18
at AsyncSeriesHook.eval [as callAsync] (eval at create (node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:22:1)
at AsyncSeriesHook.lazyCompileHook (node_modules\tapable\lib\Hook.js:154:20)
at Watching._go (node_modules\#nuxt\webpack\node_modules\webpack\lib\Watching.js:41:32)
at node_modules\#nuxt\webpack\node_modules\webpack\lib\Watching.js:33:9
at Compiler.readRecords (node_modules\#nuxt\webpack\node_modules\webpack\lib\Compiler.js:529:11)
npm i -D webpack#^4.46.0 try this, it worked for me.
I've had the same issue today, it seems to be related to an npm dependencies resolution issue.
I have opened an issue in nuxt.js repository
In my project, the issue was present, cause of #nuxtjs/eslint-module, you can remove it and regen dependencies :
npm uninstall #nuxtjs/eslint-module
rm -rf node_modules package-lock.json
npm install
You will not longer have eslint feedbacks in your build command, but you can still use npm run lint, and you will be able to use nuxt until the issue will be fixed.
I ran into this same error while trying to upgrade one of my old NuxtJS projects (using sass) built on node version 12 to version 16.
To fix this, i also installed #nuxtjs/style-resources that matches my versions of sass-loader and node-sass.
To confirm, uninstall the ones you already have, and run
npm install --save-dev node-sass sass-loader#10 fibers #nuxtjs/style-resources
see this article for more
This happened to me when I installed the most recent version of copy-webpack-plugin in Nuxt v2 project. Apparently it doesn't use webpack5 so I had to downgrade copy-webpack-plugin to last compatible version e.g. copy-webpack-plugin#4.6.0

How to replace sass variable values using grunt-sass-replace?

I want to replace few sass variable values inside a sass config file.
For example, I want to replace the value of variable "$file_global" = "new";
I want to use "grunt-sass-replace" package to do the work, i tried alot but its giving me various errors.
My Project Directory Structure:
grep/
/node_modules/
package.json
Gruntfile.js
src/
my-styles.scss
my-styles.scss Code:
$file_global: "old";
Gruntfile.js Code:
module.exports = function(grunt){
pkg: grunt.file.readJSON('package.json'),
grunt.initConfig({
'sass-replace': {
files: { // File Options
src: 'src/my-styles.scss',
dest: 'dest/my-styles.scss'
},
options: {
variables: [
{
name: 'file_global',
to: 'new'
}
]
}
}
});
grunt.loadNpmTasks('grunt-sass-replace');
grunt.registerTask('default', ['sass-replace']);
};
package.json Code:
{
"name": "grep",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "KJ",
"license": "ISC",
"devDependencies": {
"grunt": "^1.0.4",
"grunt-sass-replace": "^0.1.18",
"npm-check-updates": "^3.1.9"
}
}
I updated the "files" but its still giving me various errors.
Below are the options that i tried and the errors generated.
First Try
// Option First :
files: {
'dest/my-styles.scss': 'src/my-styles.scss'
},
ERROR :
C:\wamp64\www\GREP>grunt
>> Tasks directory "C:\wamp64\www\GREP\node_modules\grunt-sass-replace\node_modules\grunt-string-replace\tasks" not found.
Running "sass-replace:files" (sass-replace) task
Warning: no files passed. Use --force to continue..
Aborted due to warnings.
Second Try:
// Option Second :
files: [
{
src: 'src/my-styles.scss',
dest: 'dest/my-styles.scss'
}
],
ERROR :
C:\wamp64\www\GREP>grunt
>> Tasks directory "C:\wamp64\www\GREP\node_modules\grunt-sass-replace\node_modules\grunt-string-replace\tasks" not found.
Running "sass-replace:files" (sass-replace) task
Warning: pattern.indexOf is not a function Use --force to continue.
Aborted due to warnings.
Last Try:
// Option Third :
files: {
src: 'src/my-styles.scss',
dest: 'dest/my-styles.scss'
},
ERROR :
C:\wamp64\www\GREP>grunt
>> Tasks directory "C:\wamp64\www\GREP\node_modules\grunt-sass-replace\node_modules\grunt-string-replace\tasks" not found.
Running "sass-replace:files" (sass-replace) task
>> [1] scss files found in [1] passed files.
>> replacements resolved successfully.
running string-replace task.
Warning: Task "string-replace:sass" not found. Use --force to continue.
Aborted due to warnings.
Anyone know how to solve this error, or any other grunt package which can do this kind of work.
This package was last updated 3 years ago, also it uses grunt ~0.4.5. I can't help you with this, However checkout "grunt-sass-replace-values" from https://www.npmjs.com/package/grunt-sass-replace-values. This package is updated a year ago and patched.
npm install grunt-sass-replace-values --save-dev
Check out following issue on Github:
https://github.com/eliranmal/grunt-sass-replace/issues/1
Explanation :
Cause of errors :
You defined sass variable incorrectly. Variables should be defined as "$variable: value;" and not like "$variable = value;"
As of the Github issue with this package, you need to update the path to your "grunt-string-replace" dependency.
Solution :
Under your project root folder, Go to below directory:
node_modules/grunt-sass-replace/tasks
Once you're in the above directory, look for a file name "sass-replace.js"
Just open the file with any Text Editor, and Edit the path to dependency.
grunt.task.loadTasks(path.resolve(__dirname, '../node_modules/grunt-string-replace/tasks'));
In your case edit this like as below :
grunt.task.loadTasks(path.resolve(__dirname, '../../../node_modules/grunt-string-replace/tasks'));
I hope this solves your problem. If not use another package, or use older node and grunt(0.4.5) versions.

Rollup: Unresolved Dependencies

I'm having issues using npm packages with rollup (specifically lodash).
I'm getting an unresolved dependencies error. I have installed both rollup-plugin-node-resolve and rollup-plugin-commonjs and configured according to the docs. It's possible I could have missed something obvious.
Error
[~/Projects/rollup] yarn run build
yarn run v1.2.1
$ rollup -c
src/main.js → ./build/app.js...
(!) Unresolved dependencies
https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency
loadash (imported by src/main.js)
(!) Missing global variable name
Use options.globals to specify browser global variable names corresponding to external modules
loadash (guessing 'loadash')
created ./build/app.js in 47ms
✨ Done in 0.93s.
src/main.js
import { map } from 'loadash';
console.log('Test');
rollup.config.js
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
export default {
input: 'src/main.js',
output: {
file: './build/app.js',
format: 'iife'
},
plugins: [
resolve({
jsnext: true,
main: true,
browser: true,
}),
commonjs()
]
};
What am I doing wrong?
It's called lodash, not loadash!

Resources