Error: Can't resolve 'fs' and Error: Can't resolve 'path' in '.\node_modules\bindings' after libxmljs is added in angular 13 project - node.js

My angular project has started giving error during build post addition of libxmljs package. But strange thing is error is pointing to folder - \node_modules\bindings instead of \node_modules\libxmljs.
Only code change -
"libxmljs": "^0.19.7" in package.json
and
let xsdDoc = libxmljs.parseXml(xsdFile); in myproject.component.ts
My environment -
Node v18.0.0
NPM 8.6.0
No angular CLI. Its maven project.
Error log -
...
[INFO] ./node_modules/bindings/bindings.js:4:9-22 - Error: Module not found: Error: Can't resolve 'fs' in 'D:\my-frontend\node_modules\bindings'
[INFO]
[INFO] ./node_modules/bindings/bindings.js:5:11-26 - Error: Module not found: Error: Can't resolve 'path' in 'D:\my-frontend\node_modules\bindings'
[INFO]
[INFO] BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
[INFO] This is no longer the case. Verify if you need this module and configure a polyfill for it.
[INFO]
[INFO] If you want to include a polyfill, you need to:
[INFO] - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
[INFO] - install 'path-browserify'
[INFO] If you don't want to include a polyfill, you can use an empty module like this:
[INFO] resolve.fallback: { "path": false }
[INFO]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 07:51 min
...
Troubleshoot -
Tried "browser": { "fs": false, "path":false } with no luck.
Tried webpack.config.js but same issue.
Is this a bug in libxmljs and should I find other way to validate xmls ?

It seems node_modules/bindings specific bug.
I resolved issue by switching to java using javax.xml.
Sample code for war based app -
#PostMapping("/xml/validate")
public ResourceEntity<Boolean> validateXmlWithXSD(HttpServletRequest request, #RequestHeader(value = "Authorization", required = true) String token, int xsdVersion, #RequestBody ProjectXml processIn) {
//step- initializations
...
try {
//step- session validation
...
//step- xsd access from webapp
String xsdPath = "/assets/xsds/ProjectXsd." + xsdVersion + ".xsd";
InputStream xsdStream = request.getSession().getServletContext().getResourceAsStream(xsdPath);
if(xsdStream==null)
throw new NullPointerException("Null xsd stream.");
//step- xml validation against xsd
Source source = new StreamSource(xsdStream);
Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(source);
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new ByteArrayInputStream(processIn.getProcessXML())));
isValidated = true;
} catch (SAXException | IOException | NullPointerException e) {
...
}
//step- return result
}
In case of spring-boot jar app,
//step- xsd access from target/classes
String xsdPath = "/assets/xsds/ProjectXsd." + xsdVersion + ".xsd";
InputStream xsdStream = new ClassPathResource(xsdPath).getInputStream();
and in maven I configured
<resources>
<resource>
<directory>${project.build.outputDirectory}/assets/runtimeXsds</directory>
</resource>
</resources>

Related

Getting "error TS2307: Cannot find module" when deploynig code using ml-gradle

When I trying to deploying the code on ml server(10.0-9.4) ,with below build.gradle file , we are getting the below mentioned error:
In this deployment, I want to avoid the loading of ts(src/test/rule10.test.ts) file , is there any way to do so as it is not required and dependent on other modules.
command used :
./gradlew -b build.gradle loadRules -i -PmlUsername="" -PmlPassword="" -PmlHost="localhost"
build.gradle
plugins {
// node
// id "com.moowork.node" version "1.1.1"
// ML-Gradle will handle the marklogic configuration
id 'com.marklogic.ml-gradle' version '4.1.0'
id "com.github.node-gradle.node" version "3.1.1"
}
// Set up extra properties to configure ml-gradle
ext {
// set up the default IDDN databases
mlAppConfig {
contentDatabaseName = 'data1'
schemasDatabaseName = 'Schemas'
modulesDatabaseName = 'Modules'
triggersDatabaseName = 'Triggers'
}
mlAppDeployer.getCommand('DeployCustomForestsCommand').setCustomForestsPath("forests")
// mlAppDeployer.getCommands().remove(mlAppDeployer.getCommand("DeployRolesCommand"))
// do not let ml-gradle create a default rest server - we will only use the json config files
mlAppDeployer.getCommands().remove(mlAppDeployer.getCommand('DeployRestApiServersCommand'))
}
repositories {
mavenCentral()
// Needed for mlcp dependencies
maven { url 'https://developer.marklogic.com/maven2/' }
}
configurations {
mlcp
}
dependencies {
mlcp 'com.marklogic:mlcp:10.0.9.2'
mlcp files('lib')
}
// Control nodejs and NPM build tasks via gradle
node {
// Version of node to use.
version = '10.14.1'
npmVersion = '6.4.1'
download = true
}
// do not spam NPM error messages, the tools' own messages are fine.
npm_run_clean {
args = ['--loglevel', 'silent']
}
npm_run_build {
args = ['--loglevel', 'silent']
}
npm_run_test {
args = ['--loglevel', 'silent']
}
task loadJSON(type: com.marklogic.gradle.task.MlcpTask, dependsOn: []) {
classpath = configurations.mlcp
command = 'IMPORT'
database = 'Modules'
input_file_path = './src/main/ml-modules/root/a1.json'
document_type = 'json'
output_uri_replace = "^.*root,''"
}
// temp workaround to facilitate ns and collections
task loadJS(type: com.marklogic.gradle.task.MlcpTask, dependsOn: [npm_run_clean, npm_run_build]) {
classpath = configurations.mlcp
command = 'IMPORT'
database = 'Modules'
input_file_path = './src/main/ml-modules/root'
document_type = 'text'
output_uri_replace = "^.*root,''"
}
task loadRules(type: com.marklogic.gradle.task.MlcpTask, dependsOn: [mlClearModulesDatabase, mlClearSchemasDatabase, mlLoadSchemas, loadJS, loadJSON]) {
classpath = configurations.mlcp
command = 'IMPORT'
database = 'Modules'
input_file_path = './src/main/ml-modules/root'
document_type = 'text'
output_uri_replace = "^.*root,''"
output_uri_suffix = ".sjs"
}
mlLoadSchemas.mustRunAfter(mlClearSchemasDatabase)
npm_run_build{}.mustRunAfter(npm_run_clean)
loadJS.mustRunAfter(npm_run_build)
loadJS.mustRunAfter(mlClearModulesDatabase)
loadJSON.mustRunAfter(loadJS)
loadRules.mustRunAfter(loadJS)
error:
> Task :npm_run_build
Caching disabled for task ':npm_run_build' because:
Build cache is disabled
Task ':npm_run_build' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Starting process 'command '/var/opt/redaction/.gradle/npm/npm-v6.4.1/bin/npm''. Working directory: /var/opt/redaction Command: /var/opt/redaction/.gradle/npm/npm-v6.4.1/bin/npm run build --loglevel silent
Successfully started process 'command '/var/opt/redaction/.gradle/npm/npm-v6.4.1/bin/npm''
src/test/rule12.test.ts(3,38): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule11.test.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule10.test.ts(2,38): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/test7.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/test5.ts(3,36): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule3.test.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule2.test.ts(2,38): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule.test.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule1.test.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
> Task :npm_run_build FAILED
:npm_run_build (Thread[Execution worker for ':',5,main]) completed. Took 3.295 secs.
Please any one can help me on this.
You could look to apply properties to only include (or to exclude) certain module filename patterns:
https://github.com/marklogic-community/ml-gradle/wiki/Property-reference#module-and-schema-properties
mlModulesRegex New in 3.3.0 - when running mlLoadModules or mlReloadModules, only load modules with a file path matching the given regex pattern. No default value.
mlResourceFilenamesToExcludeRegex New in 3.0.0 - regex that defines resource filenames to exclude from processing (exclude = ignore). Useful for when you want to exclude a set of resources when deploying to a certain environment. Cannot be set when mlResourceFilenamesToIncludeRegex is also set. No default value.

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

Build Failure in Stromcrawler 1.16

i am using stormcrawler 1.16, apache storm 1.2.3, maven 3.6.3 and jdk 1.8.
i have created the project using the articfact command below-
mvn archetype:generate -DarchetypeGroupId=com.digitalpebble.stormcrawler -Darche typeArtifactId=storm-crawler-elasticsearch-archetype -DarchetypeVersion=LATEST
when i run mvn clean package command then i get this error -
/crawler$ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.storm:crawler >--------------------------
[INFO] Building crawler 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # crawler ---
[INFO] Deleting /home/ubuntu/crawler/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # crawler ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) # crawler ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/ubuntu/crawler/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/ubuntu/crawler/src/main/java/com/cnf/245/ESCrawlTopology.java:[19,16] ';'
expected
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.407 s
[INFO] Finished at: 2020-06-29T20:40:46Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile
(default-compile) on project crawler: Compilation failure
[ERROR] /home/ubuntu/crawler/src/main/java/com/cnf/245/ESCrawlTopology.java:[19,16] ';'
expected
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the
following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
i haven't edited pom.xml file.
Here is the content of the ESCrawlTopology.java file -
package com.cnf.245;
import org.apache.storm.metric.LoggingMetricsConsumer;
import org.apache.storm.topology.TopologyBuilder;
import org.apache.storm.tuple.Fields;
import com.digitalpebble.stormcrawler.ConfigurableTopology;
import com.digitalpebble.stormcrawler.Constants;
import com.digitalpebble.stormcrawler.bolt.FetcherBolt;
import com.digitalpebble.stormcrawler.bolt.JSoupParserBolt;
import com.digitalpebble.stormcrawler.bolt.SiteMapParserBolt;
import com.digitalpebble.stormcrawler.bolt.URLFilterBolt;
import com.digitalpebble.stormcrawler.bolt.URLPartitionerBolt;
import
com.digitalpebble.stormcrawler.elasticsearch.bolt.DeletionBolt;
import
com.digitalpebble.stormcrawler.elasticsearch.bolt.IndexerBolt;
import
com.digitalpebble.stormcrawler.elasticsearch.metrics.MetricsConsumer;
import
com.digitalpebble.stormcrawler.elasticsearch.metrics.StatusMetricsBolt;
import
com.digitalpebble.stormcrawler.elasticsearch.persistence.AggregationSpout;
import com.digitalpebble.stormcrawler.elasticsearch.persistence.StatusUpdaterBolt;
import com.digitalpebble.stormcrawler.spout.FileSpout;
import com.digitalpebble.stormcrawler.util.ConfUtils;
import com.digitalpebble.stormcrawler.util.URLStreamGrouping;
/**
* Dummy topology to play with the spouts and bolts on ElasticSearch
*/
public class ESCrawlTopology extends ConfigurableTopology {
public static void main(String[] args) throws Exception {
ConfigurableTopology.start(new ESCrawlTopology(), args);
}
#Override
protected int run(String[] args) {
TopologyBuilder builder = new TopologyBuilder();
int numWorkers = ConfUtils.getInt(getConf(), "topology.workers", 1);
if (args.length == 0) {
System.err.println("ESCrawlTopology seed_dir file_filter");
return -1;
}
// set to the real number of shards ONLY if es.status.routing is set to
// true in the configuration
int numShards = 1;
builder.setSpout("filespout", new FileSpout(args[0], args[1], true));
Fields key = new Fields("url");
builder.setBolt("filter", new URLFilterBolt())
.fieldsGrouping("filespout", Constants.StatusStreamName, key);
builder.setSpout("spout", new AggregationSpout(), numShards);
builder.setBolt("status_metrics", new StatusMetricsBolt())
.shuffleGrouping("spout");
builder.setBolt("partitioner", new URLPartitionerBolt(), numWorkers)
.shuffleGrouping("spout");
builder.setBolt("fetch", new FetcherBolt(), numWorkers)
.fieldsGrouping("partitioner", new Fields("key"));
builder.setBolt("sitemap", new SiteMapParserBolt(), numWorkers)
.localOrShuffleGrouping("fetch");
builder.setBolt("parse", new JSoupParserBolt(), numWorkers)
.localOrShuffleGrouping("sitemap");
builder.setBolt("indexer", new IndexerBolt(), numWorkers)
.localOrShuffleGrouping("parse");
builder.setBolt("status", new StatusUpdaterBolt(), numWorkers)
.fieldsGrouping("fetch", Constants.StatusStreamName,
key)
.fieldsGrouping("sitemap", Constants.StatusStreamName,
key)
.fieldsGrouping("parse", Constants.StatusStreamName,
key)
.fieldsGrouping("indexer", Constants.StatusStreamName,
key)
.customGrouping("filter", Constants.StatusStreamName,
new URLStreamGrouping());
builder.setBolt("deleter", new DeletionBolt(), numWorkers)
.localOrShuffleGrouping("status",
Constants.DELETION_STREAM_NAME);
conf.registerMetricsConsumer(MetricsConsumer.class);
conf.registerMetricsConsumer(LoggingMetricsConsumer.class);
return submit("crawl", conf, builder);
}
}
i put com.cnf.245 in groupId and crawler in articfactId.
someone please explain what cause this error ?
Can you please paste the content of ESCrawlTopology.java? Did you set com.cnf.245 as package name?
The template class gets rewritten during the execution of the archetype with the package name substituted, it could be that the value you set broke the template.
EDIT: you can't use numbers in package names in Java. See Using numbers as package names in java
Use a different package name and groupID.

Metrics with Prometheus issue using JHipster 6.0.1 (The elements [jhipster.metrics.prometheus.enabled] were left unbound.)

I'm getting an error running my JHipster application with Prometheus configuration for metrics.
I use the configuration from the official website :
https://www.jhipster.tech/monitoring/
In my application-dev.yml I have :
metrics:
prometheus:
enabled: true
And my class for auth is :
#Configuration
#Order(1)
#ConditionalOnProperty(prefix = "jhipster", name = "metrics.prometheus.enabled")
public class BasicAuthConfiguration extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/management/prometheus/**")
.authorizeRequests()
.anyRequest().hasAuthority(AuthoritiesConstants.ADMIN)
.and()
.httpBasic().realmName("jhipster")
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().csrf().disable();
}
}
2019-06-25 12:22:52.693 INFO 13260 --- [ restartedMain] com.ex.App : The following profiles are active: dev,swagger
2019-06-25 12:22:55.170 WARN 13260 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'undertowServletWebServerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedUndertow.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webConfigurer' defined in file [/home/eclipse-workspace/back_docker/target/classes/com/ex/config/WebConfigurer.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'io.github.jhipster.config.JHipsterProperties': Could not bind properties to 'JHipsterProperties' : prefix=jhipster, ignoreInvalidFields=false, ignoreUnknownFields=false; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'jhipster' to io.github.jhipster.config.JHipsterProperties
2019-06-25 12:22:55.188 ERROR 13260 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Binding to target [Bindable#7585af55 type = io.github.jhipster.config.JHipsterProperties, value = 'provided', annotations = array<Annotation>[#org.springframework.boot.context.properties.ConfigurationProperties(ignoreInvalidFields=false, ignoreUnknownFields=false, value=jhipster, prefix=jhipster)]] failed:
Property: jhipster.metrics.prometheus.enabled
Value: true
Origin: class path resource [config/application-dev.yml]:128:22
Reason: The elements [jhipster.metrics.prometheus.enabled] were left unbound.
Action:
Update your application's configuration
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.679 s
[INFO] Finished at: 2019-06-25T12:22:55+02:00
[INFO] ------------------------------------------------------------------------
I changed my JHipster project from microservice application to microservice gateway and it solved this issue.

Slack Integraton with Laravel Issues

I am trying to install slack node library, but not able to do it successfully.
I installed this library successfully on laravel 5.4 using node js. And my gulpfile is upgraded from 5.3 to 5.4 and attached below.
npm install #slack/client --save (Installation is fine but gukp is causing issue)
But when i run gulp command on shell i am getting following error:-
After adding adding this line in app.js:-
var RtmClient = require('#slack/client').RtmClient;
gulpfile.js (manually eddited)
const elixir = require('laravel-elixir');
const path = require('path');
const debug = require('gulp-debug');
const moment = require('moment');// in my gulp file
require('laravel-elixir-webpack-official');
require('laravel-elixir-vue-2');
elixir(function(mix) {
// Elixir.webpack.config.module.loaders = [];
Elixir.webpack.mergeConfig({
resolveLoader: {
root: path.join(__dirname, 'node_modules'),
},
module: {
loaders: [
{
test: /\.css$/,
loader: 'style!css'
}
]
}
});
mix.sass('app.scss')
.webpack('app.js')
.copy('node_modules/bootstrap-sass/assets/fonts/bootstrap/','public/fonts/bootstrap')
});
Error on Gulp Command
user1#console:/opt/lampp/htdocs/dev$ gulp
[15:40:27] Using gulpfile /opt/lampp/htdocs/dev/gulpfile.js
[15:40:27] Starting 'all'...
[15:40:27] Starting 'sass'...
[15:40:28] Finished 'sass' after 1.08 s
[15:40:28] Starting 'webpack'...
{ [Error: ./~/winston/package.json
Module parse failed: /opt/lampp/htdocs/dev/node_modules/winston/package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
| {
| "_args": [
| [
| {
# ./~/winston/lib/winston.js 14:18-44
# ./~/#slack/client/lib/helpers.js
# ./~/#slack/client/lib/clients/client.js
# ./~/#slack/client/lib/clients/web/client.js
# ./~/#slack/client/index.js
# ./resources/assets/js/app.js./~/winston/lib/winston/common.js
Module not found: Error: Can't resolve 'fs' in '/opt/lampp/htdocs/dev/node_modules/winston/lib/winston'
resolve 'fs' in '/opt/lampp/htdocs/dev/node_modules/winston/lib/winston'
Parsed request is a module
using description file: /opt/lampp/htdocs/dev/node_modules/winston/package.json (relative path: ./lib/winston)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /opt/lampp/htdocs/dev/node_modules/winston/package.json (relative path: ./lib/winston)
resolve as module
/opt/lampp/htdocs/dev/node_modules/node_modules doesn't exist or is not a directory
Thanks in advance

Resources