Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
TomWilloughby opened this issue Jan 16, 2020 · 1 comment · Fixed by #1351
Closed

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

TomWilloughby opened this issue Jan 16, 2020 · 1 comment · Fixed by #1351

Comments

@TomWilloughby
Copy link
Contributor

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.

@TomWilloughby
Copy link
Contributor Author

I created a pull request to fix this issue. It includes tests to cover the UNC use case and minimal code changes to pass the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant