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

Error when starting 2.2.0 'import assertion of type "json"' #26937

Closed
PatMan6889 opened this issue Apr 1, 2025 · 25 comments
Closed

Error when starting 2.2.0 'import assertion of type "json"' #26937

PatMan6889 opened this issue Apr 1, 2025 · 25 comments
Labels
problem Something isn't working

Comments

@PatMan6889
Copy link

What happened?

I updated to 2.2.0 and get this error now when I try to start:

root@Zigbee2MQTT:/opt/zigbee2mqtt# cd /opt/zigbee2mqtt && pnpm start

    [email protected] start /opt/zigbee2mqtt
    node index.js


Starting Zigbee2MQTT without watchdog.
TypeError: Module "file:///opt/zigbee2mqtt/package.json" needs an import assertion of type "json"
    at new NodeError (node:internal/errors:405:5)
    at validateAssertions (node:internal/modules/esm/assert:95:15)
    at defaultLoad (node:internal/modules/esm/load:86:3)
    at nextLoad (node:internal/modules/esm/loader:163:28)
    at ESMLoader.load (node:internal/modules/esm/loader:603:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
    at new ModuleJob (node:internal/modules/esm/module_job:64:26)
    at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:480:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34)
 ELIFECYCLE  Command failed with exit code 1.

What did you expect to happen?

To just run fine like previous versions

How to reproduce it (minimal and precise)

Upgrade from 2.1.0

Zigbee2MQTT version

2.2.0

Adapter firmware version

20230507

Adapter

Sonoff Stick

Setup

LXC on Proxmox

Debug log

No response

@PatMan6889 PatMan6889 added the problem Something isn't working label Apr 1, 2025
@Koenkk
Copy link
Owner

Koenkk commented Apr 1, 2025

Are you using any external converters or extensions?

@PatMan6889
Copy link
Author

no. just a pretty basic installation. I read something about configuration.yaml. Do I need to edit it?

@njordan77
Copy link

oh jesus, was so happy for years with v1 branch and now with v2 every update is a nitemare.
global environement variables, configuration.yaml not able to checkout,.......

Did start from scratch with 2.2.0 as 2.13 migration did not work at all....but now again im stuck at startup with the same config that worked on 2.1.3

Any idea what could be the issue...... Raspi5


pi@SmartPi:/opt/zigbee2mqtt $ sudo pnpm start

> [email protected] start /opt/zigbee2mqtt
> node index.js

Starting Zigbee2MQTT without watchdog.
[2025-04-01 22:29:03] info:     z2m: Logging to console, file (filename: log.log)
[2025-04-01 22:29:03] info:     z2m: Starting Zigbee2MQTT version 2.2.0 (commit #c5c07e7d)
[2025-04-01 22:29:03] info:     z2m: Starting zigbee-herdsman (3.4.11)

1 similar comment
@njordan77
Copy link

oh jesus, was so happy for years with v1 branch and now with v2 every update is a nitemare.
global environement variables, configuration.yaml not able to checkout,.......

Did start from scratch with 2.2.0 as 2.13 migration did not work at all....but now again im stuck at startup with the same config that worked on 2.1.3

Any idea what could be the issue...... Raspi5


pi@SmartPi:/opt/zigbee2mqtt $ sudo pnpm start

> [email protected] start /opt/zigbee2mqtt
> node index.js

Starting Zigbee2MQTT without watchdog.
[2025-04-01 22:29:03] info:     z2m: Logging to console, file (filename: log.log)
[2025-04-01 22:29:03] info:     z2m: Starting Zigbee2MQTT version 2.2.0 (commit #c5c07e7d)
[2025-04-01 22:29:03] info:     z2m: Starting zigbee-herdsman (3.4.11)

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 1, 2025

@PatMan6889 can you check the node version you are running? node --version
If v18, can you try updating to v20 or v22?


@njordan77 can you try forcing a rebuild of the serialport library?

rm -rf `find ./node_modules/.pnpm/ -wholename "*/@serialport/bindings-cpp/prebuilds" -type d`
pnpm rebuild @serialport/bindings-cpp

@njordan77
Copy link

@Nerivec

tried, made things worse....

pi@SmartPi:/opt/zigbee2mqtt $ sudo pnpm rebuild @serialport/bindings-cp
pi@SmartPi:/opt/zigbee2mqtt $ sudo pnpm start

> [email protected] start /opt/zigbee2mqtt
> node index.js

Starting Zigbee2MQTT without watchdog.

/opt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/node-gyp-build/node-gyp-build.js:60
  throw new Error('No native build was found for ' + target + '\n    loaded from: ' + dir + '\n')
        ^
Error: No native build was found for platform=linux arch=arm64 runtime=node abi=115 uv=1 armv=8 libc=glibc node=20.19.0
    loaded from: /opt/zigbee2mqtt/node_modules/.pnpm/@[email protected]/node_modules/@serialport/bindings-cpp

    at Function.load.resolve.load.path (/opt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/node-gyp-build/node-gyp-build.js:60:9)
    at load (/opt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/node-gyp-build/node-gyp-build.js:22:30)
    at Object.<anonymous> (/opt/zigbee2mqtt/node_modules/.pnpm/@[email protected]/node_modules/@serialport/bindings-cpp/dist/serialport-bindings.js:10:48)
    at Module._compile (node:internal/modules/cjs/loader:1529:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1613:10)
    at Module.load (node:internal/modules/cjs/loader:1275:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1096:12)
    at Module.require (node:internal/modules/cjs/loader:1298:19)
    at require (node:internal/modules/helpers:182:18)
    at Object.<anonymous> (/opt/zigbee2mqtt/node_modules/.pnpm/@[email protected]/node_modules/@serialport/bindings-cpp/dist/load-bindings.js:5:31)
 ELIFECYCLE  Command failed with exit code 1.

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 1, 2025

@njordan77 there's a typo in your rebuild command: @serialport/bindings-cp => @serialport/bindings-cpp
PS: If it fails again, you can always revert by rm -rf ./node_modules and pnpm i --frozen-lockfile (it will re-install the default libraries).

@njordan77
Copy link

@Nerivec

sorry for the typo, did not see myself. but still did not change anything after building serials.....

pi@SmartPi:/opt/zigbee2mqtt $ pnpm rebuild @serialport/bindings-cpp
node_modules/.pnpm/@[email protected]/node_modules/@serialport/bindings-cpp: Running install script, done in 13.7s
pi@SmartPi:/opt/zigbee2mqtt $
pi@SmartPi:/opt/zigbee2mqtt $
pi@SmartPi:/opt/zigbee2mqtt $
pi@SmartPi:/opt/zigbee2mqtt $
pi@SmartPi:/opt/zigbee2mqtt $ sudo pnpm start

> [email protected] start /opt/zigbee2mqtt
> node index.js

Starting Zigbee2MQTT without watchdog.
[2025-04-02 00:26:19] info:     z2m: Logging to console, file (filename: log.log)
[2025-04-02 00:26:19] info:     z2m: Starting Zigbee2MQTT version 2.2.0 (commit #c5c07e7d)
[2025-04-02 00:26:19] info:     z2m: Starting zigbee-herdsman (3.4.11)

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 1, 2025

Can you run with log_level: debug so we can maybe see where it's stopping more precisely?

@deflao
Copy link

deflao commented Apr 2, 2025

@Nerivec could you show me how to update to v20 or v22?

@morph027
Copy link

morph027 commented Apr 2, 2025

Same here. log_level: debug does not yield any more information.

> [email protected] start /opt/zigbee2mqtt
> node index.js

Starting Zigbee2MQTT without watchdog.
[2025-04-02 06:55:02] info:     z2m: Logging to console
[2025-04-02 06:55:02] debug:    z2m: Loaded state from file /var/lib/zigbee2mqtt/data/state.json
TypeError: Module "file:///opt/zigbee2mqtt/package.json" needs an import assertion of type "json"
    at new NodeError (node:internal/errors:405:5)
    at validateAssertions (node:internal/modules/esm/assert:94:15)
    at defaultLoad (node:internal/modules/esm/load:93:3)
    at DefaultModuleLoader.load (node:internal/modules/esm/loader:263:26)
    at DefaultModuleLoader.moduleProvider (node:internal/modules/esm/loader:179:22)
    at new ModuleJob (node:internal/modules/esm/module_job:63:26)
    at DefaultModuleLoader.#createModuleJob (node:internal/modules/esm/loader:203:17)
    at DefaultModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:156:34)
    at DefaultModuleLoader.getModuleJob (node:internal/modules/esm/loader:141:17)
    at DefaultModuleLoader.import (node:internal/modules/esm/loader:227:28)

@DJKatastrof
Copy link

I get the same error message as above

@Yougoshatenshi
Copy link

@PatMan6889 can you check the node version you are running? node --version If v18, can you try updating to v20 or v22?

updating from v18 to v22 helped for TypeError: Module "file:///opt/zigbee2mqtt/package.json" needs an import assertion of type "json"

To update: (taken from https://github.com/nodesource/distributions?tab=readme-ov-file#using-debian-as-root-nodejs-22 )
curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt-get install -y nodejs

@morph027
Copy link

morph027 commented Apr 2, 2025

Indeed, upgrading node from 20 to 22 helped.

@njordan77
Copy link

njordan77 commented Apr 2, 2025

sorry to ask, but i m confused. is the node update a different issue or this could fix the stuck situation at startup?

EDIT: tried myself to update to v22, did not change anything, still stuck at startup....

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 2, 2025

@njordan77 your issue is different from the rest of this thread. Can you set log level to debug and post the resulting logs from startup?

@njordan77
Copy link

njordan77 commented Apr 2, 2025

@Nerivec did change from info to debug. not much more insights - still stuck at this point.

> [email protected] start /opt/zigbee2mqtt
> node index.js

Starting Zigbee2MQTT without watchdog.
[2025-04-02 11:57:17] debug:    z2m: Removing old log directory '/opt/zigbee2mqtt/data/log/2025-04-01.23-06-31'
[2025-04-02 11:57:17] info:     z2m: Logging to console, file (filename: log.log)
[2025-04-02 11:57:17] debug:    z2m: Loaded state from file /opt/zigbee2mqtt/data/state.json
[2025-04-02 11:57:17] info:     z2m: Starting Zigbee2MQTT version 2.2.0 (commit #c5c07e7d)
[2025-04-02 11:57:17] info:     z2m: Starting zigbee-herdsman (3.4.11)
[2025-04-02 11:57:17] debug:    z2m: Using zigbee-herdsman with settings: '"{\"network\":{\"panID\":6772,\"extendedPanID\":[221,221,221,221,221,221,221,221],\"channelList\":[11],\"networkKey\":\"HIDDEN\"},\"databasePath\":\"/opt/zigbee2mqtt/data/database.db\",\"databaseBackupPath\":\"/opt/zigbee2mqtt/data/database.db.backup\",\"backupPath\":\"/opt/zigbee2mqtt/data/coordinator_backup.json\",\"serialPort\":{\"baudRate\":115200,\"rtscts\":false,\"path\":\"/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0\",\"adapter\":\"zstack\"},\"adapter\":{\"disableLED\":false}}"'

EDIT - some more lines coming in, mybe releveant to understand the situation

[2025-04-02 12:02:17] debug: z2m: Saving state to file /opt/zigbee2mqtt/data/state.json
[2025-04-02 12:07:17] debug: z2m: Saving state to file /opt/zigbee2mqtt/data/state.json




@Nerivec
Copy link
Collaborator

Nerivec commented Apr 2, 2025

@njordan77 and after the v22 update, did you try rebuilding serialport again? Let's try a full cleanup, to be sure:
Cleanup local libraries cache

rm -rf $(pnpm store path)

Cleanup Z2M libraries

rm -rf node_modules

Install fresh Z2M libraries

pnpm i --frozen-lockfile

Remove existing serialport prebuilds

rm -rf `find ./node_modules/.pnpm/ -wholename "*/@serialport/bindings-cpp/prebuilds" -type d`

Rebuild serialport directly for your machine (keep the all logs from this one, in case it doesn't work):

pnpm rebuild @serialport/bindings-cpp

Rebuild Z2M

pnpm run prepack

@njordan77
Copy link

njordan77 commented Apr 2, 2025

@Nerivec did all as written above (thanks for the guidelines), but it did not change anything.

here is my yaml config file, if there may be the problem located, please check. Thanks


version: 4

homeassistant:
  enabled: false
frontend:
  enabled: true
  port: 9090
mqtt:
  base_topic: /z2m
  server: mqtt://192.168.1.11:1883
  client_id: my_z2m
serial:
  adapter: zstack
  port: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
  disable_led: false
  baudrate: 115200
  rtscts: false

device_options:
  legacy: false




advanced:
  homeassistant_legacy_entity_attributes: false
  homeassistant_legacy_triggers: false
  legacy_api: false
  legacy_availability_payload: false
  pan_id: 6772
  channel: 11
  log_level: debug
  network_key:
    - 24
    - 42
  xxxxxxxxxxxxxxxxx
    - 55
devices:
  '0x0017880106735eea':
    friendly_name: PhilipsHue_Remote01
    retain: false
  '0x00158d0002882e78':

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 2, 2025

@njordan77 let's continue in the other thread, the issue is similar (this one isn't): #26556 (comment)

@Nerivec Nerivec changed the title Error when starting 2.2.0 Error when starting 2.2.0 'import assertion of type "json"' Apr 2, 2025
@jcnico
Copy link

jcnico commented Apr 2, 2025

Got the same error as reported by @PatMan6889 when updating Z2M from v2.1.0 (Proxmox/LXC installation, SLZB-06P7).
I confirm that updating pnpm as mentioned by @Yougoshatenshi solved the issue for me as well 👍

@PatMan6889
Copy link
Author

@PatMan6889 can you check the node version you are running? node --version If v18, can you try updating to v20 or v22?

updating from v18 to v22 helped for TypeError: Module "file:///opt/zigbee2mqtt/package.json" needs an import assertion of type "json"

To update: (taken from https://github.com/nodesource/distributions?tab=readme-ov-file#using-debian-as-root-nodejs-22 ) curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh sudo -E bash nodesource_setup.sh sudo apt-get install -y nodejs

Unpacking nodejs (22.14.0-1nodesource1) over (18.17.1-deb-1nodesource1) ...

Came from 18.17.1, after upgrading its running. Everything seems ok so far. Thank you!

@Koenkk
Copy link
Owner

Koenkk commented Apr 2, 2025

This doesn't seem to happen with all 18.x and 20.x versions, e.g. 18.20.5 works (but 18.17.1) doesn't indeed. Given that NodeJS 18 is EOL anyway users having this issue are advised to upgrade to a newer Node version (preferably 22).

Depending on your distro, this might be enough to fix it:

sudo curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get update
sudo apt-get upgrade -y

More details/distros here:
https://github.com/nodesource/distributions?tab=readme-ov-file#table-of-contents

@Koenkk Koenkk pinned this issue Apr 2, 2025
@deflao
Copy link

deflao commented Apr 2, 2025

Confirm that update to 22.x works. The only thing now is all devices appears offline, even though it still works

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 2, 2025

@deflao the frontend offline display bug should be fixed in dev branch (https://github.com/nurikk/zigbee2mqtt-frontend/releases/tag/0.9.6).

Repository owner locked as resolved and limited conversation to collaborators Apr 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
problem Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants