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

Cannot find module by Relative Path on Windows #389

Closed
Senryoku opened this issue Jul 24, 2021 · 2 comments · Fixed by #390
Closed

Cannot find module by Relative Path on Windows #389

Senryoku opened this issue Jul 24, 2021 · 2 comments · Fixed by #390

Comments

@Senryoku
Copy link

Senryoku commented Jul 24, 2021

Hello,

I'm trying to use a node library that uses threads.js to load a Worker with a relative path (new Worker('./file.js')). It works fine on Linux, but fail on Windows with Error: Cannot find module '\\H:\correct\absolute\path\to\file.js'
It seems to me the culprits are the \\ remaining from the file protocol, Windows likes to add what seems to be an arbitrary number of them :D

const callerPath = rawCallerPath ? rawCallerPath.replace(/^file:\//, "") : null

In my case the raw path begins with file:///H:/, patching the regex to consume additional slashes allow the worker to be loaded correctly, but this obviously won't work in other cases.
I also tried to workaround the problem by using an absolute path, but it looks like it's still treated as if it was an relative one (trying to load H:\correct\absolute\path\to\H:\correct\absolute\path\to\file.js)

As a side note, as I couldn't make sense of __non_webpack_require__ by looking at the source, this is a node application written in typescript, no webpack involved.

@andywer
Copy link
Owner

andywer commented Jul 24, 2021

Hi! Good question. Haven't touched a Windows machine in years tbh, but maybe someone else here has an idea? 👋

About the __non_webpack_require__… We only do something with it if this code is built using webpack (if typeof __non_webpack_require__ === "function"). It doesn't affect you if you are not using webpack, but without it webpack builds would not work 😉

@ruler501
Copy link
Contributor

The linked PR does fix the issue in testing so for now I'll change my dependency to that fork until it can get into an official release.

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

Successfully merging a pull request may close this issue.

3 participants