Problems using dgraph-js-http and dgraph-js with VUE

Posted by erlendoverby:

When importing dgraph-js or dgraph-js-http into VUE JS, I get errors.

Environment:

  • npm 6.3.0
  • vue-cli 3.0.0-rc.11

To replicate do the following:

vue create dgraph_project

  • select manually (babel, router, vuex)
    – the other choices are not that relevant.

cd dgraph_project
yarn add dgraph-js-http grpc dgraph-js

Add the following to the src/main.js file

import dgraph from 'dgraph-js'

yarn serve

Goto http://localhost:8080/ and check the console log in the browser.

Errors

For dgraph-js

TypeError: process.version is undefined

For dgraph-js-http

[Vue warn]: Error in render: “TypeError: dgraph_js_http__WEBPACK_IMPORTED_MODULE_0___default.a is undefined”
When I try to invoke the library by running the simple example.

I suspect that the use webpack 4 might be the reason for this problem.
However, I would appreciate if the dgraph-js library could work “out of the box” with vue-cli v3 and webpack 4.

Sorry for the trouble.

paulftw commented :

dgraph-js is Node.js only and is not supposed to work in browser.
Will take a look at what’s wrong with dgraph-js-http. It works for me with create-react-app

paulftw commented :

Closing as stale. Please try with the latest version of dgraph-js-http and re-open if it is still broken in vue.