Skip to content

Instantly share code, notes, and snippets.

@kumavis
Last active December 17, 2015 23:48
Show Gist options
  • Save kumavis/5691536 to your computer and use it in GitHub Desktop.
Save kumavis/5691536 to your computer and use it in GitHub Desktop.
browser-resolve 1.0.1 fails to locate package.json

from browser-resolve 1.0.1 index.js

// paths is mutated
// load shims from first package.json file found
function load_shims(paths, cb) {
    // identify if our file should be replaced per the browser field
    // original filename|id -> replacement
    var shims = {};

    (function next() {
        var cur_path = paths.shift();
        if (!cur_path) {
            return cb(null, shims);
        }

        var pkg_path = path.join(cur_path, 'package.json');

        fs.readFile(pkg_path, 'utf8', function(err, data) {
@kumavis
Copy link
Author

kumavis commented Jun 1, 2013

> paths
["/"]
> pkg_path
"/package.json"
> fs.readFileSync(pkg_path, 'utf8')
Error: ENOENT, no such file or directory '/package.json'
> fs.readFileSync("package.json", 'utf8')
"{
  "name": "bfs",
  "version": "0.0.0",
  "description": "ERROR: No README.md file found!",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": "",
  "author": "kumavis",
  "license": "BSD"
}"
> fs.readFileSync("./package.json", 'utf8')
"{
  "name": "bfs",
  "version": "0.0.0",
  "description": "ERROR: No README.md file found!",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": "",
  "author": "kumavis",
  "license": "BSD"
}"

@kumavis
Copy link
Author

kumavis commented Jun 1, 2013

mac os x 10.8.3

[kumavis:]$ npm -v
1.2.11
[kumavis:
]$ node -v
v0.8.21

@kumavis
Copy link
Author

kumavis commented Jun 1, 2013

that seems to only happen on this first _resolve

browserify/index.js

    return browserResolve(id, parent, function(err, file) {
> id
"/Users/kumavis/Dropbox/Development/Node/test/bfs2/index.js"

browser-resolve/index.js

function load_shims(paths, cb) {
> paths
["/", "/"]

browser-resolve/index.js

fs.readFile(pkg_path, 'utf8', function(err, data) {
> pkg_path
"/package.json"

@kumavis
Copy link
Author

kumavis commented Jun 1, 2013

second _resolve succeeds

browserify/index.js

    return browserResolve(id, parent, function(err, file) {
> id
"fs"

browser-resolve/index.js

function load_shims(paths, cb) {
> paths
["/Users/kumavis/Dropbox/Development/Node/test/bfs2", "/Users/kumavis/Dropbox/Development/Node/test", "/Users/kumavis/Dropbox/Development/Node", "/Users/kumavis/Dropbox/Development", "/Users/kumavis/Dropbox", "/Users/kumavis", "/Users", "/"]

browser-resolve/index.js

fs.readFile(pkg_path, 'utf8', function(err, data) {
> pkg_path
"/Users/kumavis/Dropbox/Development/Node/test/bfs2/package.json"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment