Add ability to import modules using absolute paths
See original GitHub issueSince working with relative paths (../../../
) can be such a pain, we should investigate adding absolute import paths to the pipeline.
This Gist outlines four possibilities:
- The Symlink
- The Global
- The Module
- The Environment
In my experience I’ve only used the NODE_PATH=
environment variable (which worked as expected), but in a complex environment like Force (and possibly Heroku, though this article seems to suggest it’s fine) there could be problems to investigate.
The Browserify Handbook also outlines some options.
Additionally, since we’re using Babel, it would be worth investigating babel-plugin-module-resolver which compiles down paths into a safe format via a config step. We’re currently using this in in Prediction.
cc @craigspaeth
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How can I import a module dynamically given the full path?
The advantage of adding a path to sys.path (over using imp) is that it simplifies things when importing more than one module from...
Read more >Use Absolute Paths with React - Better Programming
By default, relative paths are the supported way of importing modules to React and other frameworks. You will usually see or write something ......
Read more >Absolute vs Relative Imports in Python
An absolute import specifies the resource to be imported using its full path from the project's root folder. Syntax and Practical Examples. Let's...
Read more >Importing with Absolute Paths in JavaScript/TypeScript using ...
How to use absolute paths in JavaScript and TypeScript to improve your import statements, using the right webpack configuration.
Read more >Using absolute (alias) imports in Javascript and VSCode
Learn how to import javascript or typescript modules with absolute paths in webpack & VSCode. Developers love productivity hacks.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another thing I’d like to add about relative path difficulties is project exploration and especially refactoring – it’s difficult to reason about what is what and whats been used where when each path can potentially be different:
Are they all the same, or different? In terms of refactoring, one of the biggest points of stress is being able to ask yourself if a change you make to a file in one place will have cascading effects elsewhere. When pathnames are absolute, you can do a global search to see exactly where the component or whatever has been used, and safely make changes. Whole layers of complexity get removed when pathnames are locked down.
Spoke to an MS employee, they’re using the following combination:
baseUrl
option in the TS config.babel-plugin-module-resolver
to actually rewrite the paths in the resulting JS.So the babel plugin would work after all.