rdf-parse.js icon indicating copy to clipboard operation
rdf-parse.js copied to clipboard

parse method is undefined

Open bolerio opened this issue 3 years ago • 9 comments

I did npm install rdf-parse and ended up with

"rdf-parse": "^2.1.1",

in my package.json. Then doing:

import rdfParser from "rdf-parse"
....
rdfParser.parse(someStream, { contentType: 'text/turtle'})

I end up with TypeError: rdfParser.parse is not a function

bolerio avatar Nov 10 '22 22:11 bolerio

Could you try import * as rdfParser from "rdf-parse"?

rubensworks avatar Nov 11 '22 07:11 rubensworks

Thanks, @rubensworks! With this one I am getting:

error TS2339: Property 'parse' does not exist on type 'typeof import("PROJECT_HOME/node_modules/rdf-parse/lib/index")'.

23   await rdfParser.parse(S, { contentType: 'text/turtle'})

bolerio avatar Nov 11 '22 16:11 bolerio

Also just trying import { parse } from "rdf-parse" yields the error error TS2614: Module '"rdf-parse"' has no exported member 'parse'. Did you mean to use 'import parse from "rdf-parse"' instead?

It looks like here is no parse method exported from the module at all. I tried to see if I could construct an RdfParser object, but that requires an instance IRdfParserArgs for which I'd have to dig in to the depth of something called communica, and I'm not sure that's the intended usage of rdf-parse.

Do you have some sample test code/project I could run?

bolerio avatar Nov 12 '22 22:11 bolerio

Perhaps it's a problem with your tsconfig?

Example project where I'm using rdf-parse:

  • https://github.com/LinkedSoftwareDependencies/Components.js/blob/be231392dd1c5a87dc05d72c6c58b3b471bc19c6/lib/rdf/RdfParser.ts#L5
  • https://github.com/LinkedSoftwareDependencies/Components.js/blob/be231392dd1c5a87dc05d72c6c58b3b471bc19c6/tsconfig.json

rubensworks avatar Nov 14 '22 09:11 rubensworks

@rubensworks Thanks for this example. It really helps to start from a working setup! Comparing tsconfig.json with mine, seems like the main difference is I am using ES6 and not commonjs. I was able to make it work by switching to commonjs. However, I'd prefer to use ES6. Is there any chance of publishing dual packages with conditional exports as explained here.

I'm not super familiar with the node/javascript build ecosystem and I'm not sure if this is best practice or not. Found the suggestion in a SO answer. But seems like when writing new code (as is my case), aligning with the ES6 module standard is the logical choice.

bolerio avatar Nov 26 '22 07:11 bolerio

Is there any chance of publishing dual packages with conditional exports as explained here.

The problem is that tooling support for ESM is still quite shaky at the moment. Moving to ESM is something I definitely want to do in the future, but I think it's a bit too early for that at the moment.

rubensworks avatar Nov 28 '22 06:11 rubensworks

Any updates on this? (:

IgnacioNMiranda avatar Jul 04 '23 20:07 IgnacioNMiranda

No, we don't support ESM yet. CJS-only.

rubensworks avatar Jul 05 '23 06:07 rubensworks

@bolerio suggested using a dual export mechanism, that would make the module work with both ES6 and CJS, and/or publish 2 different packages.

That way you can use your CJS tooling, and maintain ES6 compatibility. Forcing people to move to CJS makes integrating with existing projects harder than it has to be.

sparkling avatar Sep 13 '23 11:09 sparkling

As of v3, we have a named export that fixes this problem.

rubensworks avatar Oct 11 '24 11:10 rubensworks