-
Notifications
You must be signed in to change notification settings - Fork 2k
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
(Windows) Invalid module when using require in JS hooks #3163
Comments
I've just tested the example locally and I'm not able to reproduce it. Make sure that the correct path to the module is used. Also note the caveat about relative paths - https://pocketbase.io/docs/js-overview/#relative-paths. Alternatively, you can also try specifying an absolute path to the file. If the above doesn't help, please a provide a minimal reproducible repo and I'll try to investigate it (it is possible to be platform specific as I'm testing on Linux, I'm not sure). |
Here is a minimal reproducible repo |
I have the same setup locally but I'm not able to reproduce it. I don't have a Windows VM at the moment to test, but I also can't think of a reason why it won't work on Windows. Are you sure that this is the code that you have locally? Do you have parent level Did you try specifying an absolute path? |
The only thing I guess that could be platform specific is the path to the file. I'll try to setup a Windows VM sometime later today and will test it. |
This is definitely the repo I'm testing with. No parent level node_modules. I get the same error no matter if path is relative or absolute and no matter which path separator I use. Tested on macOS and it works. Tested on a different Windows machine and it does not work, so pretty sure this is a Windows-only issue. |
I was able to reproduce it on a Windows 10 VM but I'm still not sure what is causing it. It works with relative path, but as mentioned in https://pocketbase.io/docs/js-overview/#relative-paths, it is relative to the current working directory: onAfterBootstrap((e) => {
const utils = require("./pb_hooks/utils.js")
utils.hello("world")
}) For some reason when the path is absolute (_hooks is the absolute path to the
I'll try to investigate it further as I'm not sure if the issue is in the upstream goja_nodejs repo or it is something specific to Windows that we'll have to take care. |
I've opened a PR in the upstream repo dop251/goja_nodejs#61. |
Should be fixed in v0.17.6 release. |
Excellent, thank you so much! |
I have copied the exact usage from the documentation: https://pocketbase.io/docs/js-overview/#loading-modules
With a main.pb.js and utils.js in pb_hooks but I get an error message when I start up pocketbase:
Platform:
Windows 11 ARM64
The text was updated successfully, but these errors were encountered: