Require-by-String does not work on the client side

Issue

Module resolution via require-by-string throws an error when invoked from the client-side.
image

Repro

  1. Create a ModuleScript in ReplicatedStorage or any other Shared container like ReplicatedFirst
  2. Create a LocalScript or a Script with RunContext set to Client
  3. Add require("../path/to/ReplicatedStorage/ModuleScript")
  4. Press play & Kaboom

The cause of this is almost certainly that StarterXXX completely changes the hierarchy of a script–notice your stack trace is now under Players.Ukendio. We should probably have a lint for this, or there should be aliases for services, or something, but I’m unsure if Luau team would want what would be necessary for require("../ReplicatedStorage/ModuleScript") to work in StarterXXX.

In the interim, I expect a Client-RunContext script in ReplicatedStorage to work.

Ah yeah it makes perfect sense that the path is different when the scripts gets cloned into the player. I don’t know why I didn’t think of that.

Some lints would be nice, and my understanding is that Roblox wants to release project-relative aliases but I am unsure whether they want to do aliases for services. That would be cool too.

And you are right that putting the script in ReplicatedStorage works.

1 Like