Skip to content

Cannot find module on windows when using -r / -x #1511

@bvella

Description

@bvella

We are building an application that embeds plugins and we are using windows.

Plugins are separate js files built with:
browserify -x react -x ./common/react/Registry.js -d plugin1/Plugin1.js -o plugin1/bundle.js
where react and ./common/react/Registry.js are shared libraries, thus excluded from the plugins' bundle using the -x switch.

Main application is built with:
browserify -r react -r ./common/react/Registry.js -d app/app.js -o app/bundle.js
where react and ./common/react/Registry.js are made available for plugins using the -r switch

We are getting the following error when loading plugins:
Uncaught Error: Cannot find module '/common\react\Registry.js'

And have tracked it down to this line being generated in plugin's bundle.js:
...},{"../../../common/react/Registry":"/common\\react\\Registry.js","react":"react"}]},{},[1])
and when manually changed to:
...},{"../../../common/react/Registry":"/common/react/Registry.js","react":"react"}]},{},[1])
works fine. Seems that some parts of browserify use the unix style path separators but others use the OS path separators.

We have changed some lines in browserify index.js such that all paths use unix style path separators. We have added .replace(//g, '/') in all cases where path is used and it seems to have fixed the problem.

Should you require a test case, we would be happy to decompose the application down to a simple test case.

Attached is a diff of the index.js file.

index.js.diff.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions