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

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.

Related

Rust-analyzer in VSCode to substitute env variables in Cargo path imports

I have a Cargo workspace and want to use a WORKSPACE_HOME environment variable in the import path of local crates.
For instance: in $WORKSPACE_HOME/services/api/Cargo.toml
[dependencies]
...
addrbook = { path = "${WORKSPACE_HOME}/pkg/addrbook" }
...
I tried adding the environment value to VSCode settings.json (under rust-analyzer.cargo.extraEnv) and also tried creating a .cargo/config.toml as described here
[env]
WORKSPACE_HOME = { value = "", relative = true }
Unfortunately, cargo metadata keeps failing saying that it is unable to resolve the path
[ERROR rust_analyzer::lsp_utils] rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /Users/nickdecooman/Documents/Workspace/foobar/Cargo.toml, Some(Version { major: 1, minor: 63, patch: 0 }): Failed to run `"cargo" "metadata" "--format-version" "1" "--manifest-path" "/Users/nickdecooman/Documents/Workspace/foobar/Cargo.toml" "--filter-platform" "x86_64-apple-darwin"`: `cargo metadata` exited with an error: error: failed to load manifest for workspace member `/Users/nickdecooman/Documents/Workspace/foobar/services/api`
Caused by:
failed to load manifest for dependency `addrbook`
Caused by:
failed to read `/Users/nickdecooman/Documents/Workspace/foobar/services/api/${WORKSPACE_HOME}/pkg/addrbook/Cargo.toml`
Caused by:
No such file or directory (os error 2)

Could not resolve org.nodejs : Local build error

I have a Angular-App forked from another repository where they manage all their builds in a pipeline.
I wanted to build that in my local system (laptop) and push the built-app in to the hosting server.
This is their build.gradle
node {
version = "9.4.0"
npmVersion = "5.6.0"
download = true
}
task cleanProd(type: Delete) {
delete "dist"
}
task testProd(type: NodeTask, dependsOn: npmInstall) {
script = file("${projectDir}/node_modules/#angular/cli/bin/ng")
args = ["test", "--browsers", "PhantomJS", "--watch=false", "--singleRun=true"]
}
task assembleProd(type: NodeTask, dependsOn: ['npmInstall', 'testProd']) {
script = file("${projectDir}/node_modules/#angular/cli/bin/ng")
args = ["build", "--prod", "--vendor-chunk=true"]
}
task copyDist(type: Copy) {
from "dist/"
into "dist/fancy-ui-${project.version}"
}
task buildProd(dependsOn: [assembleProd])
I executed the command gradlew cleanProd buildProd copyDist and I am stuck with the below exception
Build Version = build-713-ge359ca9
:cleanProd UP-TO-DATE
:nodeSetup FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':nodeSetup'.
> Could not resolve all dependencies for configuration 'detachedConfiguration1'.
> Could not resolve org.nodejs:node:9.4.0.
Required by:
:portal-ui:build-713-ge359ca9
> Could not resolve org.nodejs:node:9.4.0.
> Could not get resource 'https://nodejs.org/dist/v9.4.0/ivy.xml'.
> Could not GET 'https://nodejs.org/dist/v9.4.0/ivy.xml'.
> nodejs.org
I have all the necessary HTTP-Proxies and there is no issue with connectivity as such .. Just that this resource https://nodejs.org/dist/v9.4.0/ivy.xml is not getting loaded .. but the same code and configuration built fine in the Jenkins server
I had the same problem with node 10.14.1.
There is a workaround that solves the problem:
repositories.whenObjectAdded {
if (it instanceof IvyArtifactRepository) {
metadataSources {
artifact()
}
}
}
Extracted from https://github.com/srs/gradle-node-plugin/issues/301

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

Gradle - cannot instantiate ivy class

What am I doing wrong here? The ultimate goal is to download *.properties from the URL.
[ I know resolver is not needed, was just trying out to see if there was a class name issue. ]
Error:
build file '/home/awm/t/build.gradle': 13: unable to resolve class org.apache.ivy.plugins.resolver.URLResolver
# line 13, column 20.
def resolver = new org.apache.ivy.plugins.resolver.URLResolver()
^
build file '/home/awm/t/build.gradle': 14: unable to resolve class org.apache.ivy.util.url.ApacheURLLister
# line 14, column 21.
def urlLister = new org.apache.ivy.util.url.ApacheURLLister()
^
Code:
plugins {
id "de.undercouch.download" version "2.0.0"
}
import de.undercouch.gradle.tasks.download.Download
import org.apache.ivy.util.url.*
task downloadDirectory {
def dir = 'http://127.0.0.1:8081/artifactory/gradle-local/props/'
def resolver = new org.apache.ivy.plugins.resolver.URLResolver()
def urlLister = new org.apache.ivy.util.url.ApacheURLLister()
def files = urlLister.listFiles(new URL(dir))
download {
src files
dest "lib"
}
}
defaultTasks 'downloadDirectory'
From Gradle 2.0 on you need to include a build script dependency to Apache Ivy in order to make this recipe work. Put the following right at the beginning of your build script.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.apache.ivy:ivy:2.3.0'
}
}
example: https://github.com/michel-kraemer/gradle-download-task/blob/ddb384d3ee86f038c61ec4e77f21b814b1557a1a/examples/directory.gradle
another use-cases of download task: https://www.michel-kraemer.com/recipes-for-gradle-download/

How to run cucumber-jvm tests using Gradle

I am trying to get a project going using the new Cucumber-jvm system and Gradle as my build system.
I have used the example Java code in the GitHub cucumber-jvm project(https://github.com/cucumber/cucumber-jvm).
My project is set up in IntelliJ and the IDE is able to run the test.
However, Gradle does not find any tests to run. I know this because I broke the test and Gradle said nothing. It also said nothing when it was working.
The class it is trying to run looks like this:
import cucumber.junit.Cucumber;
import cucumber.junit.Feature;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#Feature(value = "CarMaintenance.feature")
public class FuelCarTest {
}
I'm new to both cucumber and Gradle!!
I remember having trouble with Gradle and Cucumber with the junit runner.
I eventually gave up and created a gradle task using the command line runner.
task executeFeatures(type: JavaExec, dependsOn: testClasses) {
main = "cucumber.cli.Main"
classpath += files(sourceSets.test.runtimeClasspath, file(webAppDir.path + '/WEB-INF/classes'))
args += [ '-f', 'html:build/reports/cucumber', '-g', 'uk.co.filmtrader', 'src/test/resources/features']
}
-f Folder for html report output
-g Package name for glue/step code
src/test/resources/features Where the feature files are
With the following dependencies
testCompile 'org.mockito:mockito-all:1.9.5',
'junit:junit:4.11',
'org.hamcrest:hamcrest-library:1.3',
'info.cukes:cucumber-java:1.0.14',
'info.cukes:cucumber-junit:1.0.14',
'info.cukes:cucumber-spring:1.0.14'
Update for version 4.2.5
There had been some minor changes over time:
the package name of the cli changed to cucumber.api.cli.Main
The flag -f seems no longer to be working and causes an error
So I ended up with the following task definition in my build.gradle:
task executeFeatures(type: JavaExec, dependsOn: testClasses) {
main = "cucumber.api.cli.Main"
classpath += files(sourceSets.test.runtimeClasspath)
args += [ '-g', 'uk.co.filmtrader', 'src/test/resources/features']
}
other way can be to create a task and include runner class for test
build.gradle-
task RunCukesTest(type: Test) << {
include "RunCukesTest.class"
}
testCompile 'io.cucumber:cucumber-java:4.2.0'
testCompile 'io.cucumber:cucumber-junit:4.2.0'
your class -
#RunWith(Cucumber.class)
#CucumberOptions(dryRun = false, strict = true, features = "src/test/resources", glue
= "com.gradle.featuretests",monochrome = true)
public class RunCukesTest {
}
simply hit the command :- gradle RunCukesTest
Considering:
Your .feature files are in src/test/resources/cucumber/features and
your glue classes are in com.example.myapp.glue
Then, following what is explained in the docs, you can do in build.gradle:
dependencies {
// ...
testImplementation("io.cucumber:cucumber-java:6.2.2")
testImplementation("io.cucumber:cucumber-junit:6.2.2")
testImplementation("io.cucumber:cucumber-junit-platform-engine:6.2.2")
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
// this enables the task `gradle cucumber`
task cucumber() {
dependsOn assemble, compileTestKotlin
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--strict', '--plugin', 'pretty', '--plugin', 'junit:build/test-results/cucumber.xml', '--glue', 'com.example.myapp.glue', 'src/test/resources/cucumber/features']
}
}
}
// (OPTIONAL) this makes `gradle test` also include cucumber tests
tasks.test {
finalizedBy cucumber
}
Now gradle cucumber will run the cucumber tests.
If you added the last part, gradle test will also run cucumber tests.
The args part supports what goes in the #CucumberOptions annotation of the runner. More details: https://cucumber.io/docs/cucumber/api/#list-configuration-options

Resources