Skip to content

Exception when loading .proto files stored on a UNC #1346

@TomWilloughby

Description

@TomWilloughby

protobuf.js version: 6.8.8

  • Assume I'm storing my javascript files in \\DESKTOP-2PLO61T\distributed\node\my-package\
  • Attempt to load api.proto from \\DESKTOP-2PLO61T\distributed\node\my-package\node_modules\protobufjs\google\protobuf\api.proto using Root.load()
  • util.path.resolve() calls util.path.normalize() and the path to api.proto changes to /DESKTOP-2PLO61T/distributed/node/my-package/node_modules/protobufjs/google/protobuf/api.proto
  • Note the single forward slash at the beginning of the path instead of two back slashes
  • Exception thrown because the normalized path is not a valid path to api.proto

index.js:

var path = require('path');
var Protobuf = require("protobufjs");

var sourceDir = path.join(path.dirname(require.resolve('protobufjs')), 'google', 'protobuf');
var file = path.join(sourceDir, "api.proto");
Protobuf.loadSync(file).toJSON();  // Exception

package.json:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "protobufjs": "^6.8.8"
  }
}

Exception from running node \\DESKTOP-2PLO61T\distributed\node\my-package\index.js:

\\DESKTOP-2PLO61T\distributed\node\my-package\node_modules\protobufjs\src\root.js:94
            throw err;
            ^

Error: ENOENT: no such file or directory, open '/DESKTOP-2PLO61T/distributed/node/my-package/node_modules/protobufjs/google/protobuf/api.proto'
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:343:35)
    at fetch (\\DESKTOP-2PLO61T\distributed\node\my-package\node_modules\protobufjs\src\root.js:160:34)
    at Root.load (\\DESKTOP-2PLO61T\distributed\node\my-package\node_modules\protobufjs\src\root.js:194:13)
    at Root.loadSync (\\DESKTOP-2PLO61T\distributed\node\my-package\node_modules\protobufjs\src\root.js:235:17)
    at Object.loadSync (\\DESKTOP-2PLO61T\distributed\node\my-package\node_modules\protobufjs\src\index-light.js:69:17)
    at Object.<anonymous> (\\DESKTOP-2PLO61T\distributed\node\my-package\index.js:6:10)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)

If you think this is a valid issue and there's no workaround, I'll try to find time to make a PR to address it.

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