maxlath/wikibase-sdk

Circular Dependencies, Uncaught ReferenceError: can't access lexical declaration 'simplifyEntities' before initialization

AlexW00 opened this issue ยท 7 comments

  • wikibase-sdk version: ^9.1.0
  • Environment: Firefox / Chromium latest

Error:

Uncaught ReferenceError: can't access lexical declaration 'simplifyEntities' before initialization
    <anonymous> http://localhost:4173/assets/propertyEditor-b00fceb9.js:1075

image

Bug does not occurr in development (running vite), only when building for production. Project repo: https://github.com/PDA-UR/graphit-frontend/tree/dev

Building for production is done via tsc && vite build. Vite config:

// vite.config.js
export default {
	// config options
	build: {
		outDir: "dist",
		emptyOutDir: true,
		minify: false,
		sourcemap: true,
		mode: "development",
		rollupOptions: {
			input: {
				home: "./index.html",
				visTest: "./src/pages/visTest/index.html",
				propertyEditor: "src/pages/propertyEditor/index.html",
			},
		},
	},
};

I guess the relevant code is this part, but the error doesn't give me a line number on my end. The error occurs in the sdk.

import { WBK } from "wikibase-sdk";
import type { SparqlResults } from "wikibase-sdk";

// Dont use this class directly, use the SparqlClient class instead

export default class QueryDispatcher {
	private readonly instance = "https://graphit.ur.de";
	private readonly endpoint =
		"https://query.graphit.ur.de/proxy/wdqs/bigdata/namespace/wdq/sparql";

	private readonly wbk = WBK({
		sparqlEndpoint: this.endpoint,
		instance: this.instance,
	});

	async query(sparql: string): Promise<SparqlResults> {
		const url = this.wbk.sparqlQuery(sparql);
		const headers = {};

		const response = await fetch(url, { headers });
		const data = await response.json();
		return data;
	}
}

Just tested it with Webpack, it works fine. The error only appears when using the vite build command.

it seems to be that there's a circular dependency somewhere (parse_response.js, simplify_entity.js ...)

3 circular dependencies:

madge --circular src/index.ts 
โœ– Found 3 circular dependencies!

1) helpers/helpers.ts > helpers/wikibase_time_to_date_object.ts
2) helpers/helpers.ts > types/options.ts > types/simplify_claims.ts > helpers/parse_claim.ts
3) helpers/simplify_entity.ts > helpers/simplify.ts

g

I fixed the circular dependency between simplify_entity and simplify in 2a5c61d and published that fix in v9.1.1, can you see if that resolves your problem? Other circular dependencies seem to be circular import type, which apparently can be ignored? Any opinion on this @EdJoPaTo?

I fixed the circular dependency between simplify_entity and simplify in 2a5c61d and published that fix in v9.1.1, can you see if that resolves your problem? Other circular dependencies seem to be circular import type, which apparently can be ignored? Any opinion on this @EdJoPaTo?

Thank you, the Vite build works now.

yeah, import type can be ignored as its only done on compile time with tsc. It won't end up in the actual running code. Guess specifying what to import explicitly rather than import * as simplify like it happened in 2a5c61d is always a good idea so its a good solution to that in my opinion.

As its fixed now I think this Issue can be closed then?

yes