Cesium is not building due to protobufjs error

I want to use node 20.9.0 and yarn 3.2.4.

If I do:

  1. mkdir test
  2. cd test
  3. yarn init
  4. yarn add cesium

I get the following error:

➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 1s 550ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ rbush@npm:3.0.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ topojson-client@npm:3.1.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ tslib@npm:2.6.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ undici-types@npm:5.26.5 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ urijs@npm:1.19.11 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 0s 530ms
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0007: │ protobufjs@npm:7.2.5 must be built because it never has been before or the last one failed
➤ YN0009: │ protobufjs@npm:7.2.5 couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/7r/z2yvzrzx7_lg2h81285rsplr0000gp/T/xfs-32662a81/build.log)
➤ YN0000: └ Completed in 0s 500ms
➤ YN0000: Failed with errors in 2s 593ms

The build.log file is reporting…

# This file contains the result of Yarn building a package (protobufjs@npm:7.2.5)
# Script name: postinstall


node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^
TypeError [Error]: [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "XXXX/.yarn/unplugged/protobufjs-npm-7.2.5-3439c554a5/node_modules/protobufjs/package.json" needs an import assertion of type "json"
    at load$1 (file:///XXXX/.pnp.loader.mjs:1455:17)
    at nextLoad (node:internal/modules/esm/hooks:833:28)
    at Hooks.load (node:internal/modules/esm/hooks:416:26)
    at MessagePort.handleMessage (node:internal/modules/esm/worker:168:24)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:807:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28) {
  code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING'
}

Node.js v20.9.0

Is this is known issue? Is there a solution?

I did report this issue with protobufjs as well…

I’m not sure exactly what is causing the yarn issue here, but there should be no need to run the protobufjs postinstall function.

I am hoping the people with the protobufjs project will chime in at some point. Otherwise, you may need to look at replacing or forking&fixing the problem in protobufjs in order to support building under Node 20. I am assuming there isn’t a technique on the Cesium side to work around the issue.

While I generally agree with the idea, I did want to point out that this appears to be a yarn-specific issue, not Node 20 itself.

Our CI installs, builds, and installs cesium in a smokescreen project successfully under Node 20.

Interesting. I will investigate further. Perhaps a newer version of yarn fixes the issue. Thanks for letting me know.

1 Like

Confirmed. It is a yarn specific issue. I started checking yarn versions between 3.2.4 and 4.0.2 and the issue went away starting with yarn 3.6.3.

Thank you for checking this for me and leading me to the solution.

1 Like