frontend maven plugin - Cannot find module - angularjs

I user frontend-maven-plugin in my project. I have already installed node, npm and bower on my machine. When I run "mvn clean install" I get the below error.
node --version -> v5.7.1
npm --version -> 3.6.0
bower --version
-> 1.7.7
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- NB! Set <version> to the latest released version of frontend-maven-plugin,
like in README.md -->
<version>1.3</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<!-- See https://nodejs.org/en/download/ for latest node and npm (lts)
versions -->
<nodeVersion>v5.10.1</nodeVersion>
<npmVersion>3.8.3</npmVersion>
<!-- optional: where to download node from. Defaults to https://nodejs.org/dist/ -->
<nodeDownloadRoot>https://artifacts.apple.com/node-distributions/</nodeDownloadRoot>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<!-- optional: The default argument is actually "install", so unless
you need to run some other npm command, you can remove this whole <configuration>
section. -->
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>bower install</id>
<goals>
<goal>bower</goal>
</goals>
<configuration>
<!-- optional: The default argument is actually "install", so unless
you need to run some other bower command, you can remove this whole <configuration>
section. -->
<!-- <workingDirectory>.</workingDirectory>
<installDirectory>./src/main/webapp/</installDirectory> -->
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>gulp build</id>
<goals>
<goal>gulp</goal>
</goals>
<!-- optional: the default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<!-- optional: if not specified, it will run Grunt's default task
(and you can remove this whole <configuration> section.) -->
<arguments>build</arguments>
</configuration>
</execution>
</executions>
</plugin>
Getting the below error,
[INFO] --- frontend-maven-plugin:1.3:bower (bower install) # cs-web ---
[INFO] Running 'bower install' in cs-web
[ERROR] module.js:341
[ERROR] throw err;
[ERROR] ^
[ERROR]
[ERROR] Error: Cannot find module 'cs-web/node_modules/bower/bin/bower'
[ERROR] at Function.Module._resolveFilename (module.js:339:15)
[ERROR] at Function.Module._load (module.js:290:25)
[ERROR] at Function.Module.runMain (module.js:447:10)
[ERROR] at startup (node.js:146:18)
[ERROR] at node.js:404:3

Related

How to set REACT_APP_ROUTER_BASE for react app when configured with Jetty server

I have created a test react project and were trying to host it on Jetty server. My pom.xml looks like this :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!--
Adapted from:
https://gist.github.com/phillipgreenii/7c954e3c3911e5c32bd0
-->
<modelVersion>4.0.0</modelVersion>
<groupId>it.megadix</groupId>
<artifactId>create-react-app-hello-world</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<npm.output.directory>build</npm.output.directory>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Standard plugin to generate WAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webResources>
<resource>
<directory>${npm.output.directory}</directory>
</resource>
</webResources>
<webXml>${basedir}/web.xml</webXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<!-- Required: The following will ensure `npm install` is called
before anything else during the 'Default Lifecycle' -->
<execution>
<id>npm install (initialize)</id>
<goals>
<goal>exec</goal>
</goals>
<phase>initialize</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>
<!-- Required: The following will ensure `npm install` is called
before anything else during the 'Clean Lifecycle' -->
<execution>
<id>npm install (clean)</id>
<goals>
<goal>exec</goal>
</goals>
<phase>pre-clean</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>
<!-- Required: This following calls `npm run build` where 'build' is
the script name I used in my project, change this if yours is
different -->
<execution>
<id>npm run build (compile)</id>
<goals>
<goal>exec</goal>
</goals>
<phase>compile</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<environmentVariables>
<CI>true</CI>
<!-- The following parameters create an NPM sandbox for CI -->
<NPM_CONFIG_PREFIX>${basedir}/npm</NPM_CONFIG_PREFIX>
<NPM_CONFIG_CACHE>${NPM_CONFIG_PREFIX}/cache</NPM_CONFIG_CACHE>
<NPM_CONFIG_TMP>${project.build.directory}/npmtmp</NPM_CONFIG_TMP>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<!--<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<environmentVariables>
<PUBLIC_URL>http://localhost:8080/${project.artifactId}</PUBLIC_URL>
<REACT_APP_ROUTER_BASE>/${project.artifactId}</REACT_APP_ROUTER_BASE>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>-->
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<environmentVariables>
<PUBLIC_URL>http://153.214.189.19:8080/${project.artifactId}</PUBLIC_URL>
<REACT_APP_ROUTER_BASE>/${project.artifactId}</REACT_APP_ROUTER_BASE>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
I have built this project using Maven.
[INFO] Building war: C:\Users\gpoo\source\repos\react\hello-world\target\create-react-app-hello-world.war
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored
(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:54 min
[INFO] Finished at: 2022-06-02T12:52:44+05:30
[INFO] ------------------------------------------------------------------------
PS C:\Users\gpoo\source\repos\react\hello-world>
On jetty have created a .xml file, which sets the context manager.
[root#node1 webapps]# cat create-react-app-hello-world.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/create-react-app-hello-world</Set>
<Set name="war">/tmp/create-react-app-hello-world.war</Set>
</Configure>
In spite of this, i am unable to get the output:
GET http://153.214.189.19:8080/static/js/main.f64f7128.chunk.js net::ERR_ABORTED 404 (Not Found)
Please guide me.

How to fix maven build error failed to execute goal com.github.eirslett?

I'm following an example from this link to develop a simple crud app.
Everything works fine until I try to run it with the the -Pprod parameter so that it runs as a single app:
./mvnw spring-boot:run -Pprod
Then it comes up with this error:
ERROR] error Command "build" not found.
[INFO] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.571 s
[INFO] Finished at: 2020-04-21T23:18:42-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.6:yarn (yarn build) on project licensing-app: Failed to run task: 'yarn build' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
Here's the relevant portion of pom.xml:
<id>prod</id>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/static</outputDirectory>
<resources>
<resource>
<directory>app/build</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<configuration>
<workingDirectory>app</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<yarnVersion>${yarn.version}</yarnVersion>
</configuration>
</execution>
<execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>yarn test</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>test</phase>
<configuration>
<arguments>test</arguments>
<environmentVariables>
<CI>true</CI>
</environmentVariables>
</configuration>
</execution>
<execution>
<id>yarn build</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>compile</phase>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
</profile>
Any idea what might be causing this?
I just tried cloning the repo:
git clone git#github.com:oktadeveloper/okta-spring-boot-react-crud-example.git
And running the command you mentioned:
cd okta-spring-boot-react-crud-example
./mvnw spring-boot:run -Pprod
Works on my machine! 😊
2020-04-22 12:21:16.891 INFO 79919 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-04-22 12:21:16.897 INFO 79919 --- [ main] c.o.d.jugtours.JugToursApplication : Started JugToursApplication in 5.59 seconds (JVM running for 46.727)
2020-04-22 12:21:16.978 INFO 79919 --- [ main] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
Group(id=1, name=Denver JUG, address=null, city=null, stateOrProvince=null, country=null, postalCode=null, user=null, events=[Event(id=5, date=2018-12-12T18:00:00Z, title=Full Stack Reactive, description=Reactive with Spring Boot + React, attendees=[])])
Group(id=2, name=Utah JUG, address=null, city=null, stateOrProvince=null, country=null, postalCode=null, user=null, events=[])
Group(id=3, name=Seattle JUG, address=null, city=null, stateOrProvince=null, country=null, postalCode=null, user=null, events=[])
Group(id=4, name=Richmond JUG, address=null, city=null, stateOrProvince=null, country=null, postalCode=null, user=null, events=[])

Upload React Application to Nexus

I built a React-Application using create-react-app.
The production build is done on Jenkins via:
npm install --prod
npm run build
Then I have the "ready to deploy" artifact.
But how can I get this artifact on my Nexus-Server?
Can i use the version from package.json?
Do I have to make a zip or something like that on my own before uploading?
This would be pretty nice to have a history and it would be easier/faster to build dockers from the artifact on nexus than building again.
How you guys solved that?
Thanks for answers.
I know this question is old, but it might help others.
I recently had to do something similar. My approach was:
Convert the project to a Maven one
Configure my private repository in pom.xml
<distributionManagement>
<snapshotRepository>
<id>RepoId</id>
<url>http://.../repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>RepoId</id>
<url>http://.../repositories/releases/</url>
</repository>
</distributionManagement>
Configure maven clean plugin to empty the build directory
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>build</directory>
<includes>
<include>**/*</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
Configure maven jar plugin to skip the jar creation
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
Integrate frontend-maven-plugin - my project needed yarn, but it can also run with npm
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.12.1</version>
<executions>
<!-- install node & yarn -->
<execution>
<id>install node and yarn</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
<configuration>
<nodeVersion>v16.13.0</nodeVersion>
<yarnVersion>v1.22.17</yarnVersion>
</configuration>
</execution>
<!-- yarn install -->
<execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
</execution>
<!-- yarn run build -->
<execution>
<id>yarn run build</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
Integrate maven assembly plugin in order to pack everything under build directory into a zip file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<!-- pack everything under /build into a zip -->
<execution>
<id>create-distribution</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
where assembly.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>build</directory>
</fileSet>
</fileSets>
</assembly>
Finally run mvn clean deploy in order to get the zip file uploaded to nexus.
Also, I found this solutions for synchronizing the package.json version with the pom.xml version, but I did not use it.

build-helper-maven-plugin report error sources is missing

I try to use build-helper-maven-plugin 1.9 to add integration test folder, Pom shows below:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/integrate/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
the maven version is 3.2.2, when I run mvn build-helper:add-source, it throws errors below:
[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:1.8:add-source (default-cli) on project test: The parameters 'sources' for
goal org.codehaus.mojo:build-helper-maven-plugin:1.8:add-source are missing or invalid -> [Help 1]
appreciate any help
Fix it in Eclipse with install APT M2E Connector, m2e Connector for build-helper-maven-plugin.
now the folder shows in Eclipse correctly.

How to install/deploy artifacts compiled by make-maven-plugin

I'm using the make-maven-plugin to build a software written in C with Maven. My goal is to automatically install and deploy the source tarball AND the binary artifact to the Maven repository when I run mvn install and mvn deploy. My current pom.xml looks like this:
<project>
<groupId>myGroup</groupId>
<artifactId>myProject</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>make-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<configuration>
<destDir>${project.build.directory}/dest</destDir>
<workDir>${basedir}</workDir>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>package</id>
<phase>package</phase>
<goals>
<goal>make-dist</goal>
</goals>
<configuration>
<skipDist>false</skipDist>
<sourceArchive>${project.name}-${project.version}.tar.bz2</sourceArchive>
<sourceArchivePath>${project.build.directory}</sourceArchivePath>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I package the project then I have the following files in the target directory:
myProject-2.0.bin (The compiled binary artifact)
myProject-2.0.tar.bz2 (The source tar ball)
When running mvn install then the created source tar ball and the POM file is installed to the local maven repository. How can I tell Maven to also install the binary file? I don't want to copy it by hand.
Attach the binary file as an artifact using build-helper-maven-plugin

Resources