skip to Main Content

I have a constantly running tcp raw socket that I can connect to using an existing app. I am trying to use socket.io-client in my photoshop plugin, but after installing, my require() statements fail no matter what kind of relative path or whatever I use. npm sees no issues, and I have tried reinstalling as well. I have to use socket.io because all the provided network IO modules with Photoshop UXP are unable to connect to raw TCP.

Process

  1. I start a terminal in the same folder as my index.js and existing package.json.
  2. I run npm install socket.io-client
  3. it succeeds. I now have a node_modules folder and a package-lock.json
  4. I am unable to use socket.io-client anywhere in my project.

In index.js, these fail, when I am pretty sure they shouldn’t:

const io = require('socket.io-client')
const io = require('./node_modules/socket.io-client')
const {io} = require('socket.io-client')

and so on, even using an absolute path.

When I try this in index.js, the failure is always:
"Module not found: <any/path/to/socket.io-client>. Parent folder was "./"

Other things I have tried:

  • uninstalling/deleting node_modules folder and package-lock and trying again.
  • Installing using the -global argument.
  • using npm ls to see that socket.io-client is actually installed.

I have looked everywhere online for help, but I can’t find anyone with a similar problem, please help!

2

Answers


  1. Chosen as BEST ANSWER

    I figured this out. Photoshop plugins (UXP) use a custom JavaScript engine that doesn't check node_modules during require(). There is a forum post I can provide a link to as a source when I am not on mobile. It might work if I use Webpack or other bundling module.


  2. Try to use destructuring assignment:

    const { io } = require("socket.io-client");
    

    Reference: Socket IO Documentation

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search