Unable to require() file in new version of PS, but it works in 24.1.0

I am updating PS version to 25.2 from 24.1.0 and my plugin stopped working. It would appear that certain paths for require() aren’t valid anymore. For example, I have two .js files:

/js/document/document.js
and
/dialogs/newFileDialog/newFileDialog.js

this works: require('./js/document/document.js')
this raises an error: require('./dialogs/newFileDialog/newFileDialog.js')
The error is uninformative. It isnt an error Object, its just the string “-4058” which I think means file not found?

But If I go back to PS 24.1.0, nothing is broken. How do I fix this?

I think this is caused by the number of characters in a file path.

I made another test file in the same dialogs folder and that one imported via require no problem.

Then I made one with a super long name, e.g. dialogs/extremelyLongNameExample/extremelyLongNameExample.js

and that one also gives the cryptic error.

I guess I’ll be renaming a lot of my folders, then!

Just kidding, its still broken even if I shorten it.

The solution is that UXP silently enforces a new filepath standard in the fs module.

They decided to change it so that anytime you use the fs module, such as fs.readdir(), you cant use relative paths such as '../my/path' anymore. You have to use 'plugin:/path/to/folder' and always path to things from the plugin root. It would appear you have three options, which are only enumerated in the middle of a paragraph on one doc page, as a passing remark. Here

“plugin:”, “plugin-data:”, and “plugin-temp:”, as well as a native “file:” scheme for the path parameter.

as for what each of those plugin schemes actually map to, its your guess :man_shrugging:

The file I was trying to require() had a fs.readdir() call in it using relative paths, which are not allowed now. Wish the error messaging would just like, tell me that.

1 Like

You could also use bundler e.g. webpack to workaround this.