Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28037] iOS: Relative path require not working with node_modules

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2021-03-10T16:05:16.000+0000
Affected Version/sn/a
Fix Version/sRelease 10.0.0
ComponentsiOS
Labelsgriffin-app, ios, node_modules, require
ReporterBrenton House
AssigneeChristopher Williams
Created2020-07-22T22:26:03.000+0000
Updated2021-06-16T15:45:25.000+0000

Description

On iOS, when doing a relative path require from within a file that exists in node_modules, a runtime error occurs: [ERROR] message = "Couldn't find module: ./subdir/test3 for architecture: x86_64"; I've created a standalone test project for this issue here: https://github.com/brentonhouse/TIMOB-28037

Comments

  1. Jan Vennemann 2020-07-22

    This seems to be a general issue when doing lazy requires of relative paths in subfolders on iOS. We only store one global "working directory" which we update while evaluating files, and reset it once done. Requires that are evaluated later, e.g. calling require in a function exported by a module, will then use a wrong base dir to resolve the relative path.
  2. Brenton House 2020-09-02

    FYI - I am able to workaround this issue using a babel plugin in Turbo that resolves static relative paths for all require statements to the absolute path of the module that is being loaded. This fixes a majority of the cases and should serve as a solid workaround until this issue is resolved.
  3. Brenton House 2020-09-02

    It seems that files in the node_modules directory are skipped from babel processing. I can fix that in Turbo as well but I am not sure what the original intention was with skipping these.
  4. Jan Vennemann 2020-09-16

    [~bhouse], not 100% sure right now if we specifically exclude node_modules or babel does it on its own, but files inside node_modules are generally expected to be ready-to-use without any transpilation needs. That's because node_modules can get pretty huge and processing all files in there would unnecessarily slow down the build
  5. Christopher Williams 2021-02-25

    https://github.com/appcelerator/titanium_mobile/pull/11447
  6. Christopher Williams 2021-03-10

    Fixed in https://github.com/appcelerator/titanium_mobile/pull/11693

JSON Source