Search code examples
node.jsmavennpmvaadinvaadin14

vaadin-maven-plugin npm registry configuration


For context, I'm running a jenkins build which has no direct internet access. We have a nexus with proxy repositories for maven, nodejs and npm.

I'm using the recommended frontend-maven-plugin to download and install node and npm. This step works fine. Afterwards the vaadin-maven-plugin is used with the prepare-frontend and build-frontend goals.

Apparently, this triggers the actual npm install so I need it to contact the private npm registry, yet I can't find any setting to specify this. I did find a npmRegistryURL variable in the vaadin-maven-plugin configuration, but apparently this isn't used for the build-frontend goal.

My pom setup looks like this:

    <build>
        <plugins>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <phase>generate-resources</phase>
                    </execution>
                </executions>
                <configuration>
                    <nodeVersion>v12.13.0</nodeVersion>
                    <nodeDownloadRoot>https://nexusrepo.com/repository/nodejs/</nodeDownloadRoot>
                    <npmDownloadRoot>https://nexusrepo.com/repository/npmjs/</npmDownloadRoot>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>prep</id>
                        <goals>
                            <goal>prepare-frontend</goal>
                            <goal>build-frontend</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <npmRegistryURL>https://nexusrepo.com/repository/npmjs/</npmRegistryURL>
                </configuration>
            </plugin>
        </plugins>
    </build>

I've also tried to let the frontend-maven-plugin handle the npm install but that doesn't work because the vaadin-maven-plugin is manually adding extras to the node_modules/@vaadin folder. So I got the same Error: Cannot find module '@vaadin/stats-plugin' as specified in Vaadin issue 10306

I've also tried to add a .npmrc file to the root of my project to specify the npm registry, but that had no effect. Should this work or is it simply not checked by the vaadin-maven-plugin?

Some help would be greatly appreciated. I can't manually configure the node installation by using npm config set registry because it's not a static node installation, so the configuration needs to happen inside of the actual maven build.


Solution

  • After quite a bit of searching and testing, there seem to be 2 ways of solving this problem.

    Option 1 is to configure the frontend-maven-plugin with an npm execution/goal.
    The default argument is install, but it doesn't have to be. That way you can use this execution to run the npm config set registry command.

        <execution>
            <id>npm config</id>
            <goals>
                <goal>npm</goal>
            </goals>
            <configuration>
                <arguments>config set registry https://nexusrepo.com/repository/npmjs/</arguments>
            </configuration>
            <phase>generate-resources</phase>
        </execution>
    

    WARNING: from my experience, this saves the given registry in a user folder .npmrc file, which would probably affect every npm build on your jenkins, since it would save it for the default jenkins-user. Therefore, this did not seem like a proper solution.

    Option 2 is adding a .npmrc file to the root of your project.
    I tried doing this at first but it didn't work (as specified in the question). This only seemed to be the case on my local workstation, probably because I also had nodejs and npm actually installed and the settings were being overridden somewhere else. During the jenkins build this worked as intended.

    Option 2 definitely seemed like the better way to go forward, so that's what I did for now. Still annoyed by the lack of vaadin-maven-plugin documentation, but at least I got it to work.