browserify / browserify/browserify

getting error requiring files added through a stream via their `file`

Open
#1,622 4 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

I'm getting an error thrown from the `resolve` module when I attempt to require a stream by its provided `file`, when that file doesn't exist on the file system.

``` js
const path = require('path')
const Readable = require('stream').Readable
const Browserify = require('browserify')

const s1 = new Readable()
s1.push('module.exports = function () { console.log("s1 required") }')
s1.push(null)
s1.file = path.resolve('./s1.js')

const s2 = new Readable()
s2.push('require("./s1")()')
s2.push(null)
s2.file = path.resolve('./s2.js')

const b = new Browserify()
b.add(s1)
b.add(s2)
b.bundle().pipe(process.stdout)

//events.js:160
// throw er; // Unhandled 'error' event
// ^
//
//Error: Cannot find module './s1' from 'C:\Code\browserify-tests'
// at C:\Code\browserify-tests\node_modules\resolve\lib\async.js:55:21
// at load (C:\Code\browserify-tests\node_modules\resolve\lib\async.js:69:43)
// at onex (C:\Code\browserify-tests\node_modules\resolve\lib\async.js:92:31)
// at C:\Code\browserify-tests\node_modules\resolve\lib\async.js:22:47
// at FSReqWrap.oncomplete (fs.js:123:15)
```

The truly maddening thing is if I create a dummy file where it's looking it will gladly go along it's way and everything else works properly (I can require the contents added via stream properly by its `file`)

``` js
const fs = require('fs')
const path = require('path')
const Readable = require('stream').Readable
const Browserify = require('browserify')

const s1 = new Readable()
s1.push('module.exports = function () { console.log("s1 required") }')
s1.push(null)
s1.file = path.resolve('./s1.js')
fs.writeFileSync(s1.file, '') // gross

const s2 = new Readable()
s2.push('require("./s1")()')
s2.push(null)
s2.file = path.resolve('./s2.js')
fs.writeFileSync(s2.file, '') // gross

const b = new Browserify()
b.add(s1)
b.add(s2)
b.bundle().pipe(process.stdout) // a-ok

//{1:[function(require,module,exports){
//module.exports = function () { console.log("s1 required") }
//},{}],2:[function(require,module,exports){
//require("./s1")()
//},{"./s1":1}]},{},[1,2])
```

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.