Despite my extensive search for a solution to this issue, I have been unsuccessful so far – even after referring to the amazing gist on improving local require paths and thoroughly reading the Browserify handbook section on Avoiding ../../../../... I am struggling to find a viable solution for this problem.
I am currently working on a library developed with Browserify, which I intend to publish on npm. You can check it out yourself if you wish to test what I am describing here. However, the challenge lies in my desire to release it on NPM without relying on relative paths when calling require()
, as it is done when using Browserify.
By utilizing Browserify's opts.paths
, I managed to transform my require()
s from conventional forms like
var Classy$Base = require('./base')
// and in another file
var Classy$Module = require('../../module')
to
var Classy$Base = require('classy/base')
// and in another file
var Classy$Module = require('classy/module')
This modification was successful and effective! When I execute gulp bundle
, I receive a functional classy.bundle.js
output, making everything seem right.
However, upon performing a npm link
and linking it in another project (also using Browserify) via npm link classy-js
, things start to fall apart. Error messages originating from require('classy-js')
claim instances of "could not find module 'classy/base' from 'node_modules/classy-js/src...'" among others.
I envision creating a library where I can simply call require('classy-js')
, along with
require('classy-js/classy/module')
to access all other beneficial submodules of the library whilst maintaining non-relative paths within the library's code.
Is there any feasible way to achieve this?
I experimented with app-module-path, which unfortunately results in Browserify errors, and I also tested require-root with similar outcomes.
I tried symlinks and incorporated an npm postInstall script for automatically setting up symlinks, yet nothing seemed to work.
It feels like this should be a more straightforward process...