Skip to content

@serialport/list, @serialport/terminal requires 'package.json' to run #2972

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

Open
serg3295 opened this issue Dec 26, 2024 · 3 comments · May be fixed by #3034
Open

@serialport/list, @serialport/terminal requires 'package.json' to run #2972

serg3295 opened this issue Dec 26, 2024 · 3 comments · May be fixed by #3034

Comments

@serg3295
Copy link

serg3295 commented Dec 26, 2024

SerialPort Version

13.0.0

Node Version

v20.18.1

Electron Version

No response

Platform

Linux Lenovo 6.8.0-51-generic #52-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec 5 13:09:44 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Architecture

x64

Hardware or chipset of serialport

esp32, esp8266

What steps will reproduce the bug?

npx @serialport/terminal
npx @serialport/list

What happens?

Crash log
❯ npx @serialport/terminal
node:fs:448
  return binding.readFileUtf8(path, stringToFlags(options.flag));
                 ^

Error: ENOENT: no such file or directory, open '../package.json'
  at readFileSync (node:fs:448:20)
  at Object.<anonymous> (/home/serg/Projects/js/begin/node_modules/.pnpm/@[email protected]/node_modules/@serialport/terminal/dist/index.js:13:59)
  at Module._compile (node:internal/modules/cjs/loader:1469:14)
  at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
  at Module.load (node:internal/modules/cjs/loader:1288:32)
  at Module._load (node:internal/modules/cjs/loader:1104:12)
  at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:173:12)
  at node:internal/main/run_main_module:28:49 {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '../package.json'
}

Node.js v20.18.1

❯ npx @serialport/list
node:fs:448
  return binding.readFileUtf8(path, stringToFlags(options.flag));
                 ^

Error: ENOENT: no such file or directory, open '../package.json'
  at readFileSync (node:fs:448:20)
  at Object.<anonymous> (/home/serg/Projects/js/begin/node_modules/.pnpm/@[email protected]/node_modules/@serialport/list/dist/index.js:7:59)
  at Module._compile (node:internal/modules/cjs/loader:1469:14)
  at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
  at Module.load (node:internal/modules/cjs/loader:1288:32)
  at Module._load (node:internal/modules/cjs/loader:1104:12)
  at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:173:12)
  at node:internal/main/run_main_module:28:49 {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '../package.json'
}

❯ npx @serialport/repl
No arduinos found. You must specify a port to load.

For example:
      serialport-repl COM3
      serialport-repl /dev/tty.my-serialport

Node.js v20.18.1

What should have happened?

The @serialport/list, @serialport/terminal should run without additional 'package.json'

Additional information

I added ../package.json:

{
  "version": "0.1.0",
  "description": "testing"
}

the @serialport/list, @serialport/terminal started working.

@ebaauw
Copy link

ebaauw commented Jan 9, 2025

Problem is that package.json is now read using readFileSync(), which uses the current directory as base, instead of require(), which uses the programme directory.

@matt-oakes
Copy link

I have opened a small PR which fixes this issue #3034

In the meantime, you can edit the file referenced in the crash log and add __dirname to the path so it will run correctly.

@tkurki
Copy link

tkurki commented May 20, 2025

I just bumped against this using npx @serialport/list per documentation at https://serialport.io/docs/bin-list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants