Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Maven to automatically install Node.js & npm #6262

Open
basil-bourque opened this issue Aug 15, 2019 · 2 comments
Open

Configure Maven to automatically install Node.js & npm #6262

basil-bourque opened this issue Aug 15, 2019 · 2 comments

Comments

@basil-bourque
Copy link

I was disappointed to find that after downloading a new Vaadin 14 project from the Get Started page via the Plain Java Servlet option, I could not run the project.

I received the following error message on the console.

[ERROR] Failed to execute goal com.vaadin:vaadin-maven-plugin:14.0.0:prepare-frontend (default) on project acme: Execution default of goal com.vaadin:vaadin-maven-plugin:14.0.0:prepare-frontend failed: 
[ERROR] 
[ERROR] ======================================================================================================
[ERROR] Failed to determine 'node' tool.
[ERROR] Please install it either:
[ERROR]   - by following the https://nodejs.org/en/download/ guide to install it globally
[ERROR]   - or by running the frontend-maven-plugin goal to install it in this project:
[ERROR]   $ mvn com.github.eirslett:frontend-maven-plugin:1.7.6:install-node-and-npm -DnodeVersion="v10.16.0" 
[ERROR] ======================================================================================================
[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/PluginExecutionException

Apparently the Vaadin team decided to not include Node.js and npm within each Vaadin 14 project. I suggest this was a poor choice for a few reasons:

  • Not being able to run the freshly created project makes for a bad first impression for anyone new to Vaadin. And it makes a frustrating annoyance to anyone already familiar with Vaadin.
  • It would be easier for people to learn how to later remove node/npm-per-project (if they so chose) than it is for people to learn how to install node/npm.
  • To my mind at least, the core raison d'être behind Vaadin is so that developers can work mainly in Java, without needing to master JavaScript, HTML, CSS, DOM, WebSocket, Push, and such. Having to learn what is Node.js and what is npm, and then learn how to install them goes against the main value proposition for Vaadin. Your interest in Vaadin-on-Java has been waning obviously, so If this is no longer core to the mission of your company, I ask you to say so clearly, so we Java-oriented users and customers can make plans to move on to other platforms.

The workaround I found is to add the frontend-maven-plugin in my Maven configuration.

<plugin>
    <groupId>com.github.eirslett</groupId>
    <artifactId>frontend-maven-plugin</artifactId>
    <!-- Use the latest released version:
    https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
    <version>1.8.0</version>

    <executions>
        <execution>
            <!-- optional: you don't really need execution ids, but it looks nice in your build log. -->
            <id>install node and npm</id>
            <goals>
                <goal>install-node-and-npm</goal>
            </goals>
            <!-- optional: default phase is "generate-resources" -->
            <phase>generate-resources</phase>
        </execution>
    </executions>
    <configuration>
        <nodeVersion>v10.16.2</nodeVersion>

        <!-- optional: with node version greater than 4.0.0 will use npm provided by node distribution -->
        <!--                    <npmVersion>2.15.9</npmVersion>-->

        <!-- optional: where to download node and npm from. Defaults to https://nodejs.org/dist/ -->
        <!--                    <downloadRoot>http://myproxy.example.org/nodejs/</downloadRoot>-->
    </configuration>
</plugin>

If you insist on maintaining your decision to omit node/npm, then at least do:

  • Post instructions on how to add node/npm globally and/or per-project
  • Post an explanation as to the downsides or problems with including node/npm in each project. Marcus Hellberg on your blog mentions: "became clear that it was less than ideal having Node installed in each project folder", but he did not explain the issues.
  • If working mainly in Java to use Vaadin is no longer viable, and you now expect Vaadin users to be savvy with Node, npm, JavaScript, and such , say so clearly so we can decide to stay that course or move to other platforms.

For more discussion, see:

@marcushellberg
Copy link
Member

There's also a related ticket, #6249, which discusses automatically installing node in a central location so it wouldn't need to be duplicated across projects.

@Legioth
Copy link
Member

Legioth commented Aug 16, 2019

You are right that there's still things to improve with regard to documentation around this topic. With that said, I'd like to clarify the high level picture.

The challenge with frontend-maven-plugin is that it downloads a node installation into the project directory. In practice, this means that you'll end up downloading the same stuff at least once per project you're working on and then again and again every time the download target location has been cleared. In particular, this slows down CI builds since those are typically always run from an empty starting position to reduce the risk of side effects. For this reason, we chose to make a local node installation the default and then instruct users to use frontend-maven-plugin as a special case.

At the same time, having node installed is the only thing we "require" from Vaadin developers. We don't assume that they will directly interact with node in an way. We don't assume they will manually run node or any related tools. We don't assume the user will be configuring anything specific to those tools. Vaadin is supposed to handle all those things automatically on behalf of the user, even though there are also always situations when things don't work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants