Open vemonet opened 2 years ago
import N3 from 'n3';
This is weird, I expect
import { DataFactory } from 'n3';
I imported it this way to follow as closely as possible the example given in the readme, if I directly import DataFactory with import { DataFactory } from 'n3';
I am getting the same error in the console:
Uncaught SyntaxError: import not found: default N3Lexer.js:3:7
It seems to be due to the queueMicrotask
import:
import queueMicrotask from './../../queue-microtask/index.js';
Currently this index.js is:
/*! queue-microtask. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
let promise
module.exports = typeof queueMicrotask === 'function'
? queueMicrotask.bind(typeof window !== 'undefined' ? window : global)
// reuse resolved promise, and allocate it lazily
: cb => (promise || (promise = Promise.resolve()))
.then(cb)
.catch(err => setTimeout(() => { throw err }, 0))
But it should be converted to an ES module, something like this:
/*! queue-microtask. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
let promise
export default typeof queueMicrotask === 'function'
? queueMicrotask.bind(typeof window !== 'undefined' ? window : global)
// reuse resolved promise, and allocate it lazily
: cb => (promise || (promise = Promise.resolve()))
.then(cb)
.catch(err => setTimeout(() => { throw err }, 0))
There is a pull request about this actually: https://github.com/feross/queue-microtask/pull/19 but no response
Yeah, queue-microtask needs to fix their stuff, or you could adjust your packer/environment configuration.
But it seems that queueMicrotask
is now widely supported; we could drop Node 10 and take it from there.
I agree, the queueMicrotasks import also creates issues when trying to use N3 in a web worker. (since this line throws queueMicrotask.bind(typeof window !== 'undefined' ? window : global)
)
Hi, @jeswr @RubenVerborgh I am trying to use
n3
in a Web Component built using Lit Element, so in-browser javascript, but there seems to be issues withn3
imports (which also impacts usingrdflib.js
)I am trying to run the basic example provided by the docs after installing with
yarn add n3
in a Web Componentcontructor()
:I am getting this error in the console when importing
n3
(also happens when working withrdflib
):Note that removing all lines related to n3 apart from the import will fix the component and it will work
The problematic line in
N3Lexer.js
is the last one withqueue-microtask
Just in case, I tried to solve it with:
And I can find an
index.js
in thenode_modules/queue-microtask
but I am still getting theimport not found
error in the consoleThe here are the dependencies and their versions used in my
package.json
:Do you have any idea why I am getting this error? Is it an issue on
n3
side or something related to the Web Component design?Note that currently I am just trying to parse a RDF string (e.g. turtle) to an object I can search in (with the usual
.get(undefined, undefined, undefined)
functions for example or SPARQL). But every solution I found out there for JS was failing (mostly because they were relying ofn3
for parsing turtle I think)I am also open if you have any suggestions of better libraries/approach to do this in the browser! :)