neo4j-javascript-driver icon indicating copy to clipboard operation
neo4j-javascript-driver copied to clipboard

Can it be used as a module in the browser?

Open LeMoussel opened this issue 5 years ago • 2 comments

Browsers have had support for loading ECMAScript modules directly (no tools like Webpack required)

in index.html, I do this

<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="UTF-8">
    <script type="module" src="neo4j.js"></script>
  </head>
  <body>
   // Do some stuff ....
  </body>
</html>

in neo4j.js

/*jshint esversion: 6 */

import neo4j from 'https://unpkg.com/[email protected]/lib/browser/neo4j-web.min.js';

I got this error

SyntaxError: The requested module 'https://unpkg.com/[email protected]/lib/browser/neo4j-web.min.js' does not provide an export named 'default'

With this

/*jshint esversion: 6 */

import { neo4j } from 'https://unpkg.com/[email protected]/lib/browser/neo4j-web.min.js';

I got

SyntaxError: The requested module 'https://unpkg.com/[email protected]/lib/browser/neo4j-web.min.js' does not provide an export named 'neo4j'

Is possible to use neo4j-javascript-driver has module in browser?

LeMoussel avatar Dec 29 '19 09:12 LeMoussel

Hi @LeMoussel,

We currently does not support esversion 6. You can found more info about using this driver in browser in https://github.com/neo4j/neo4j-javascript-driver#in-web-browser

Cheers, Zhen

zhenlineo avatar Jan 14 '20 15:01 zhenlineo

Hi @zhenlineo I think it could be cool to have this package compiled as a ESM, this could perhaps use my usecase in deno where I use:

import neo4j from "https://cdn.skypack.dev/neo4j-driver";

To import both the .d.ts files and the lib it self, not sure if this is something that could be worked on easily making a ESM package? and in the mean time maybe look at some export map as described here: https://docs.skypack.dev/package-authors/package-checks#export-map (this is rather new to my self, but I do find it interesting), I see you are already doing something similar with unpkg and jsdeliver.

edit link to the skypack repo: https://www.skypack.dev/view/neo4j-driver

Nopzen avatar May 27 '21 14:05 Nopzen

This can be done since 5.4.0, more about it on https://www.npmjs.com/package/neo4j-driver#in-web-browser

bigmontz avatar Oct 27 '23 10:10 bigmontz