[TIMOB-28037] iOS: Relative path require not working with node_modules
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2021-03-10T16:05:16.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 10.0.0 |
Components | iOS |
Labels | griffin-app, ios, node_modules, require |
Reporter | Brenton House |
Assignee | Christopher Williams |
Created | 2020-07-22T22:26:03.000+0000 |
Updated | 2021-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
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.
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.
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.
[~bhouse], not 100% sure right now if we specifically exclude
node_modules
or babel does it on its own, but files insidenode_modules
are generally expected to be ready-to-use without any transpilation needs. That's becausenode_modules
can get pretty huge and processing all files in there would unnecessarily slow down the buildhttps://github.com/appcelerator/titanium_mobile/pull/11447
Fixed in https://github.com/appcelerator/titanium_mobile/pull/11693