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

Unable to use with rollup #162

Closed
quentincaffeino opened this issue Mar 5, 2020 · 4 comments
Closed

Unable to use with rollup #162

quentincaffeino opened this issue Mar 5, 2020 · 4 comments

Comments

@quentincaffeino
Copy link

quentincaffeino commented Mar 5, 2020

By importing hydra (import {Hydra} from 'alcaeus';) I get this error

[!] Error: 'promises' is not exported by node_modules/jsonld/lib/index.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/alcaeus/lib/es/MediaTypeProcessors/RdfProcessor.js (2:9)
1: import JsonLdSerializer from '@rdfjs/serializer-jsonld';
2: import { promises as jsonld } from 'jsonld';
            ^
3: import $rdf from 'rdf-ext';
4: import stringToStream from 'string-to-stream';
Error: 'promises' is not exported by node_modules/jsonld/lib/index.js
    at error (/app/node_modules/rollup/dist/shared/node-entry.js:5400:30)
    at Module.error (/app/node_modules/rollup/dist/shared/node-entry.js:9820:16)
    at handleMissingExport (/app/node_modules/rollup/dist/shared/node-entry.js:9721:28)
    at Module.traceVariable (/app/node_modules/rollup/dist/shared/node-entry.js:10159:24)
    at ModuleScope.findVariable (/app/node_modules/rollup/dist/shared/node-entry.js:8766:39)
    at FunctionScope.findVariable (/app/node_modules/rollup/dist/shared/node-entry.js:3065:38)
    at ChildScope.findVariable (/app/node_modules/rollup/dist/shared/node-entry.js:3065:38)
    at MemberExpression.bind (/app/node_modules/rollup/dist/shared/node-entry.js:6530:49)
    at CallExpression$1.bind (/app/node_modules/rollup/dist/shared/node-entry.js:3152:23)
    at CallExpression$1.bind (/app/node_modules/rollup/dist/shared/node-entry.js:6718:15)

Replication steps:

  1. Create new project yarn init
  2. Add rollup yarn add rollup @rollup/plugin-node-resolve @rollup/plugin-commonjs
  3. Create minimal rollup configuration file rollup.config.js with this content:
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'

module.exports = {
  input: 'main.js',
  output: {
    file: 'bundle.js',
    format: 'es'
  },
  plugins: [ resolve({ browser: true }), commonjs() ]
};
  1. Create file to compile main.js:
import { Hydra as client } from 'alcaeus';
client.loadResource('https://sources.test.wikibus.org/');
  1. Compile with rollup main.js --config rollup.config.js

Other

Is this package event meant to be used in browser? No demos on website does not work either.
And it isn't specified anywhere what is the primary platform for this package.

@tpluscode
Copy link
Member

Alcaeus itself is built to both commonjs and modules (note the /es/ segment in imported path).

However, many of its dependencies which are all targeted at node js only. That includes jsonld as well as all the RDF/JS packages and node streams.

That said, I have not really used it with rollup. I will have to investigate

@tpluscode
Copy link
Member

tpluscode commented Apr 22, 2020

Hello again @quentincaffeino
I'm nearing a 1.0 version (will beta soon) and I though I would give this a go.

I think I can fix the problem you experience by changing some of the commonjs imports. This is related to default exports, module.exports and how rollup resolves them. You can read more on rollup/plugins#71 and rollup wiki

Unfortunately there is also a bigger problem with readable-stream. See nodejs/readable-stream#348. This is the wall I've currently just hit and don't know how to fix...

For the time being, you would be stuck with webpack, which I have been using successfully for a long time.

@quentincaffeino
Copy link
Author

Thanks for your time anyway!

@tpluscode
Copy link
Member

There is little I can do from alcaeus perspective. Will close this now

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

No branches or pull requests

2 participants