question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document how to avoid relative paths hell

See original GitHub issue

The paths option, that forwards to https://github.com/defunctzombie/node-browser-resolve is not documented here

In my browserify app, for my private JS code, I don’t want to use relative paths because it’s annoying when you move some code from one place to another to have to update all the relative paths. See http://stackoverflow.com/a/23608416/82609

It seems the paths option permits to make available your own js files like normal node modules. As far as I have seen it works pretty fine and the browserify app is being build without using relative paths.

The problem is that in my paths folders I have JSX React files that must be compiled to JS before being integrated by browserify. It seems browserify doesn’t transform these files unless I reference them with their relative paths. I don’t know if this is a bug or an intended behavior. I think it could be nice, for each path, to specify if we want it to be transformed by browserify or not. Currently my browserify bundle contains raw uncompiled JSX code, and it breaks at runtime.

Until now I did not find any clear solution on how to handle the relative paths everywhere problem. I think it’s a pretty common problem that can be really annoying on large code base when refactoring. It’s also solved easily with requirejs so I guess it would be nice to document how to do it with browserify.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:25 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
ghostcommented, May 16, 2014

The problem is that there are a ton of ways to do what you’re trying to do. For me, the best thing is just to put code in node_modules/ so that require() will resolve them without any configuration necessary.

4reactions
ghostcommented, May 19, 2014

For each of your modules in node_modules/, you can configure the package.json with its own browserify transform field. Then your transforms will be applied automatically and in such a way that changes to modules will be isolated from one another. That is really handy when you need to evolve a project over time so you don’t need to switch everything over at once. You can just update the pieces as you need to.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid relative path hell in JavaScript / TypeScript projects
Relative path hell is a common pain point on large JavaScript/TypeScript projects. Learn how Webpack can help you avoid this problem.
Read more >
escaping relative path require hell in Node.js - Corey Cleary
Keep npm modules for more library-ish things. Please note: the following two solutions will require updating for migration to Node's ES Modules implementation....
Read more >
Avoid relative path import hell in react - DEV Community ‍ ‍
I have created web applications in react using this tool. For file imports in a folder tree that is not deep, relative import...
Read more >
Get rid of relative import path hell by adding absolute imports ...
Imagine one day you have to update the directory structure meaning part of or all of the relative paths must be changed.
Read more >
Solving the Long Relative Paths Problem Natively in Node.JS
Learn to solve the long relative path, or relative path hell, problem the correct way in Node JS using native Node tools and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found