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

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?

Related

How to resolve circular dependency in compilation of node modules?

I am using yarn workspaces and have a project (proj1) which uses a library I wrote (proj2), which had been initialised with create-react-library when I started it. My library uses visx in some of the components. Everything was fine until I added the last line in my index.js file, exporting another component that is build with visx:
export { ConfigField } from './ConfigField';
export { ConfigPage } from './ConfigPage';
export { SaveButton } from './SaveButton';
export { PageLoadingIndicator } from './PageLoadingIndicator';
export { UsersPage } from './UsersPage';
export { AnalyticValue } from './AnalyticValue';
export { DonutChart } from './DonutChart';
export { SingleValueDonutChart } from './SingleValueDonutChart';
export { Alert } from './Alert';
export { FormDialog } from './FormDialog';
export { TimeSeriesChart } from './TimeSeriesChart';
Somehow, after the addition of this export, when building proj2 a circular dependency is created. I suspect this is to do with compiling to have CJS imports.
PS C:\usr\git\proj2> yarn
yarn install v1.22.5
warning package.json: No license field
[1/4] Resolving packages...
success Already up-to-date.
$ run-s build
yarn run v1.22.5
warning package.json: No license field
$ microbundle-crl --no-compress --format modern,cjs
Circular dependency: ..\node_modules\#visx\axis\esm\index.js -> ..\node_modules\#visx\axis\esm\axis\Axis.js -> ..\node_modules\#visx\axis\esm\axis\AxisRenderer.js -> ..\node_modules\#visx\axis\esm\index.js
Non-existent export 'TextProps' is imported from ..\node_modules\#visx\text\esm\types.js
Error: 'TextProps' is not exported by ..\node_modules\#visx\text\esm\types.js, imported by ..\node_modules\#visx\text\esm\Text.js
at C:\usr\git\proj1\node_modules\#visx\text\esm\Text.js:8:9
6: import useText from './hooks/useText';
7: import { TextProps } from './types';
8: export { TextProps } from './types';
^
9: var SVG_STYLE = {
10: overflow: 'visible'
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "build" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
How can I fix this circular dependency? Is there a plugin I should be using?
Solved. The problem was actually pretty basic. I realised I was importing from #visx/axis without having it explicitly in my package.json. 🤦 After adding explicitly, it works.

setup webpack config in nextJS (next.config.js)

I'm working with NextJS and using react-data-export plugin to generate xls files.
in the description it says :
This library uses file-saver and xlsx and using
json-loader will do the magic for you.
///webpack.config.js
vendor: [
.....
'xlsx',
'file-saver'
],
.....
node: {fs: 'empty'},
externals: [
{'./cptable': 'var cptable'},
{'./jszip': 'jszip'}
]
but I have no idea how to implement it and got error like this :
The static directory has been deprecated in favor of the public directory. https://err.sh/vercel/next.js/static-dir-deprecated
Defining routes from exportPathMap
event - compiled successfully
> Ready on http://localhost:80 or http://localhost
> Ready on https://localhost:443 or https://localhost
event - build page: /menu_accounting/ReportGross
wait - compiling...
error - ./node_modules/react-export-excel/node_modules/xlsx/xlsx.js
Module not found: Can't resolve 'fs' in '/home/ahmadb/repos/lorry-erp/node_modules/react-export-excel/node_modules/xlsx'
Could not find files for /menu_accounting/ReportGross in .next/build-manifest.json
I had the same problem, the solution for me was this:
Install this packages (if you installed, ignored this)
npm install file-saver --save
npm install xlsx
npm install --save-dev json-loader
Add this to your nextjs.config.js
const path = require('path')
module.exports = {
...
//Add this lines
webpack: (config, { isServer }) => {
// Fixes npm packages that depend on `fs` module
if (!isServer) {
config.node = {
fs: 'empty'
}
}
return config
}
}

Babel-loader 8 complains about not finding deprecated babel-preset-es2015

with this webpack config:
{ test: /\.tsx?$/,
use:[
{
loader:'babel-loader',
options: {
presets:['#babel/preset-env']
}
},
{
loader:'ts-loader'
}]
},
I get an error message Error: Cannot find module 'babel-preset-es2015'
If I add that module I get two errors
babel-preset-es2015 is deprecated, use babel-preset-env
But when I install babel-preset-env I still get error about not finding babel-preset-es2015
When I install babel-preset-es2015 I get the error
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/henrikbechmann/Servers/tribalopolis/www/tribalopolis.com/node_modules/babel-preset-es2015/lib/index.js
So it's a complete trap!
Any suggestions?
Answer: Mostly a matter of updating .babelrc
{
"presets": [
"#babel/env",
"#babel/react"
]
}
and of course updating modules
tip: try npx update-babel

Kerberos library is not installed

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.

Google closure gives error while javascript minificatation

I am using google-closure-compiler grunt task to minify javascript files. I've defined task like : -
'closure-compiler': {
deviceDetails: {
files: {
'target.min.js: 'source.js'
},
options: {
compilation_level: 'SIMPLE'
}
// args: [
// '--js', 'source.js',
// '--compilation_level', 'SIMPLE',
// '--js_output_file', 'out.js',
// '--debug'
// ]
}
This gives me an error
[ { '29': 1,
_state: 2,
_result: [Error: not implemented],
_subscribers: [] } ]
Warning: Compilation error Use --force to continue.
Aborted due to warnings.
Earlier I was facing promise issue , for that I installed pollyfill module.
require('es6-promise').polyfill();
I am running npm 1.3.10 version and Unfortunately, I can't upgrade it right now.
Also , followed alternative approach of using args.. still facing same error.
So after bit analysis, I am using below two grunt plugin's
1. grunt-closure-tools
2. google-closure-compiler
Its was a problem with legacy npm version.

Resources