browserify / browserify/browserify

How can I require a file that is built using browserify?

Open
#1,773 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.7k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Hello browserify lords :)

I built a js library using browserify. Working well in the browser and everything looks great if I put it as a separate file in my html:
```

```
But when I want to require the library file in my app, browserify complains.
Because the `require`s are still in the file and if I re-bundle it, browserify wants to re-include the files that are already included.

My files:
```
- library
- src
- core.js
- foo.js
- build.js
- app
- src
- core.js
- build.js
```
`library/src/foo.js`:
```
module.exports = 'foo';
```
`library/src/core.js`:
```
console.log(require('./foo'));
```
`app/src/core.js`:
```
require('../../library/build');
```
`library/build.js` is created using browserify:
```
$ browserify library/src/core.js > library/build.js
```

**Now I want to build `app/src/core.js` the same way (`$ browserify app/src/core.js > app/build.js`) but it complains: `Error: Cannot find module './foo' from '/library'`**

I created a test repo to demo the issue: https://github.com/saeedseyfi/browserify-issue

Please advise.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.