Can't build Javascript add-on (org.openhab.automation.jsscripting)

  • Platform information:
    • Hardware: x86 Mac
    • Java Runtime Environment: Oracle JDK 21.0.4
    • openHAB version: 5.0.0-SNAPSHOT (head of the git repo today)
    • Maven 3.9.9, Node 14.15.0

I’m unable to build openhab-addons; I get the following error, and I’m guessing it’s because I don’t have quite the right build stack, and honestly, I don’t even know how to troubleshoot this. Can someone provide guidance?

[INFO] --- frontend:1.15.1:npx (npx webpack (openhab-js globals injection)) @ org.openhab.automation.jsscripting ---
[INFO] Running 'npx webpack -c ./node_modules/openhab/build/@globals-webpack.config.js --entry-reset --entry ./node_modules/openhab/build/@openhab-globals.js -o ./dist' in /Users/jerry/Documents/dev/openhab/openhab-addons/bundles/org.openhab.automation.jsscripting/target/js
[INFO] [webpack-cli] Failed to load '/Users/jerry/Documents/dev/openhab/openhab-addons/bundles/org.openhab.automation.jsscripting/target/js/node_modules/openhab/build/@globals-webpack.config.js' config
[INFO] [webpack-cli] Error: Cannot find module '/Users/jerry/Documents/dev/openhab/openhab-addons/bundles/org.openhab.automation.jsscripting/target/js/node_modules/openhab/build/@globals-webpack.config.js'
[INFO] Require stack:
[INFO] - /Users/jerry/node_modules/webpack-cli/lib/webpack-cli.js
[INFO] - /Users/jerry/node_modules/webpack-cli/lib/bootstrap.js
[INFO] - /Users/jerry/node_modules/webpack-cli/bin/cli.js
[INFO] - /Users/jerry/node_modules/webpack/bin/webpack.js
[INFO]     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
[INFO]     at Function.Module._load (node:internal/modules/cjs/loader:804:27)
[INFO]     at Module.require (node:internal/modules/cjs/loader:1028:19)
[INFO]     at require (node:internal/modules/cjs/helpers:102:18)
[INFO]     at WebpackCLI.tryRequireThenImport (/Users/jerry/node_modules/webpack-cli/lib/webpack-cli.js:223:30)
[INFO]     at loadConfigByPath (/Users/jerry/node_modules/webpack-cli/lib/webpack-cli.js:1406:38)
[INFO]     at /Users/jerry/node_modules/webpack-cli/lib/webpack-cli.js:1460:88
[INFO]     at Array.map (<anonymous>)
[INFO]     at WebpackCLI.loadConfig (/Users/jerry/node_modules/webpack-cli/lib/webpack-cli.js:1460:68)
[INFO]     at WebpackCLI.createCompiler (/Users/jerry/node_modules/webpack-cli/lib/webpack-cli.js:1781:33) {
[INFO]   code: 'MODULE_NOT_FOUND',
[INFO]   requireStack: [
[INFO]     '/Users/jerry/node_modules/webpack-cli/lib/webpack-cli.js',
[INFO]     '/Users/jerry/node_modules/webpack-cli/lib/bootstrap.js',
[INFO]     '/Users/jerry/node_modules/webpack-cli/bin/cli.js',
[INFO]     '/Users/jerry/node_modules/webpack/bin/webpack.js'
[INFO]   ]
[INFO] }

Welcome to the openHAB community!

1 Like

@jdandrews what command did you use to build openhab-addons? Were you trying to build all addons, or just jsscripting specifically?

1 Like

Command: mvn test

I started building the whole project, which failed at jsscripting.

Then I cd’d into to that single project and did mvn test, which failed the same way.

I noted that with core, I needed to build one of the test modules first, but I don’t see the “problem module” with jsscripting (perhaps I don’t know how to read the output for that build properly).

Futher troubleshooting: The missing file appears to be @globals-webpack.config.js. I ran the following:

jerry@JDA-MacBook-Pro openhab-addons % find ~/node_modules -name "*globals-web*"
/Users/jerry/node_modules/openhab/build/@globals-webpack.config.js
jerry@JDA-MacBook-Pro openhab-addons % pwd  
/Users/jerry/Documents/dev/openhab/openhab-addons
jerry@JDA-MacBook-Pro openhab-addons % find . -name "@globals-web*"
jerry@JDA-MacBook-Pro openhab-addons % 

So it looks like the file they want is there, but something in the build isn’t copying it to the build output directory. Presumably this project builds successfully, so there’s something I’m missing regarding how to set it up to build properly… and I’m not sure how to correct that, as I’ve never seen a js project built with maven before.

This section of the POM seems to be the problem. The command line seems to indicate that npx expects a local .node_modules directory; I really only have a global one, so this would work if the “.” in `./node_modules/openhab…’ was present in my project, but it isn’t, and I’m not sure what the “correct” way to get it there is.

          <execution>
            <id>npx webpack (openhab-js globals injection)</id>
            <goals>
              <goal>npx</goal>
            </goals>
            <configuration>
              <!--suppress UnresolvedMavenProperty -->
              <arguments>webpack -c ./node_modules/openhab/build/@globals-webpack.config.js --entry-reset --entry
                ./node_modules/openhab/build/@openhab-globals.js -o ./dist</arguments>
            </configuration>
          </execution>
          <execution>
            <id>npx webpack (openhab-js)</id>
            <goals>
              <goal>npx</goal>
            </goals>
            <configuration>
              <!--suppress UnresolvedMavenProperty -->
              <arguments>webpack -c ./node_modules/openhab/build/webpack.config.js --entry-reset --entry
                ./node_modules/openhab/ -o ./dist</arguments>
            </configuration>
          </execution>

I should mention that I use a default maven configuration that the openhab build complains about (it doesn’t recognize some of the (probably outdated) properties). But removing ~/.m2/settings.xml doesn’t affect the problem above.

1 Like