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

(Windows) Invalid module when using require in JS hooks #3163

Closed
jf908 opened this issue Aug 19, 2023 · 9 comments
Closed

(Windows) Invalid module when using require in JS hooks #3163

jf908 opened this issue Aug 19, 2023 · 9 comments

Comments

@jf908
Copy link

jf908 commented Aug 19, 2023

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:

2023/08/19 15:27:03 GoError: Invalid module at github.com/dop251/goja_nodejs/require.(*RequireModule).require-fm (native)

Platform:
Windows 11 ARM64

@ganigeorgiev
Copy link
Member

ganigeorgiev commented Aug 19, 2023

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).

@jf908
Copy link
Author

jf908 commented Aug 19, 2023

Here is a minimal reproducible repo

https://github.com/jf908/pb_repro

@ganigeorgiev
Copy link
Member

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 node_modules that eventually could conflict with the module?

Did you try specifying an absolute path?

@ganigeorgiev ganigeorgiev reopened this Aug 19, 2023
@ganigeorgiev
Copy link
Member

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.

@ganigeorgiev ganigeorgiev changed the title Bug: Invalid module when using require in JS hooks (Windows) Invalid module when using require in JS hooks Aug 19, 2023
@jf908
Copy link
Author

jf908 commented Aug 19, 2023

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.

@ganigeorgiev
Copy link
Member

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 pb_hooks dir) it doesn't work, aka. the following fails to open:

C:\Users\IEUser\pb_hooks\utils.js

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.

@ganigeorgiev
Copy link
Member

I've opened a PR in the upstream repo dop251/goja_nodejs#61.

@ganigeorgiev
Copy link
Member

Should be fixed in v0.17.6 release.

@jf908
Copy link
Author

jf908 commented Aug 21, 2023

Excellent, thank you so much!

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

No branches or pull requests

2 participants