How to specify node version for Maven in CDK Builds

Viewed 539

When I try to run unit tests on my CDK Java project with mvn test, I get an error that Node v8.9.1 has reached end-of-life and is not supported..

But Node v12.22.1 is my current version, which I check right before running Maven.

node --version
v12.22.1
mvn test
....

Curiously, if I run Maven through the IntelliJ GUI, it works.

I have set my node version with nvm, if that matters. And I'm on a Mac.

Is there some environment variable I need to set? How does the CDK determine which node to use?

Any ideas?

Thanks!

Full output:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!!                                                                                  !!

!!  Node v8.9.1 has reached end-of-life and is not supported.                       !!

!!  You may to encounter runtime issues, and should switch to a supported release.  !!

!!                                                                                  !!

!!  As of the current release, supported versions of node are:                      !!

!!  - ^12.7.0                                                                       !!

!!  - ^14.5.0                                                                       !!

!!  - ^16.3.0                                                                       !!

!!                                                                                  !!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

(node:14462) Warning: process.on(SIGPROF) is reserved while debugging

/private/var/folders/nr/dkx1p38s24nb7fx_qgcxggcm0000gn/T/jsii-java-runtime8055040669944096944/lib/program.js:467
            } catch {
                    ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:599:28)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
2 Answers

Two things could be causing this.

  1. In your build spec, you haven't specified the runtime env as node. Even if you manually install node yourself, and the --version command returns it, when the commands run on your code build it will use the default. You have to define it in your codebuild buildspec.yaml with:
    phases:
      install:
         runtime-versions:
           nodejs: 12

If you don't specify this runtime-version, then any commands run - such as mvn - that are not direct node commands will automatically use 8.9.1

  1. assuming you have already provided this in your buildspec, then the other potential problem is your Codebuild Image. If you are not set to Standard2.0 or greater, then you cannot make use of runtimes- they will always default to the base runtimes of node 8. (see this reference for docker images on codebuild available ) -- Unless you really need to otherwise, you should be using Ubuntu Standard 5.0. It has the most recent backend code that utilizes the Buildspec and gives you the most control.

It is worth noting, if you are using CDK, and you don't specify a specific image to use it automatically defaults to Standard1.0 and the runtime-versions will be ignored. More annoyingly, if you are in Standard1.0 it will print a warning that runtime-versions is ignored but not stop the process... and since codebuilds ignore the --quiet flags of most commands, it can very easily get lost in the spam.

The Surefire plugin is using my /usr/local/bin/node, which was not installed with nvm. It was 8.9.1. I upgraded that node version and it works.

Related