Description
Hi,
plugin is used to append 'index' to the module path of a require/import.
Adding 'index' to the path prevents browserify to work properly.
For instance, we have a local package module1 with such package.json
{
"name": "module1",
"browser": {
"./env": "./env/index-browser.js",
"./ipc": "./ipc/index-browser.js",
I have a module module2 using module1
import { ipcPubSub, IpcPubSub } from 'module1/ipc';
import { GetElectronEnvironment } from 'module1/env';
I remap module1 location to another path in 'module2 tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"module1/*": ["./build/module1/*"],
},
}
}
I compile and get
const env_1 = require("../../module1/env/index");
const ipc_1 = require("../../module1/ipc/index");
Browserify do not try to look at the module1 package as you have an explicit file 'index' mentioned in the require. Then it does not map module1/env
to module1/env/index-browser.js
and the generated bundle is wrong and most of the time failed to be generated as referencing api not compatible with a browser. I do not try with webpack but the resolution strategy is supposed to be the same.
Could it be possible to keep the path untouched, else, I'm afraid, such strategy, based on package.json 'browser' field, always failed.
Thanks
Issue summary
(Addendum by @nonara)
In cases like require('#path1')
, where this resolves to /path1/index.js
, the compiled output is require('/path1/index')
. It should more preferably be require('/path1')
, opting not to write the implicit index
filename portion of the path.
As mentioned by OP, this seems to specifically also cause breaking issues with npm's browser
config.