deepl-node icon indicating copy to clipboard operation
deepl-node copied to clipboard

Circular dependency index.js ➜ parsing.js ➜ index.js

Open WarningImHack3r opened this issue 1 year ago • 4 comments

Describe the bug

When building my Svelte app that uses deepl-node, I get a warning about circular dependencies:

Circular dependency: node_modules/.pnpm/[email protected]/node_modules/deepl-node/dist/index.js -> node_modules/.pnpm/[email protected]/node_modules/deepl-node/dist/parsing.js -> node_modules/.pnpm/[email protected]/node_modules/deepl-node/dist/index.js

To Reproduce Steps to reproduce the behavior:

  1. Create a (Svelte) app
  2. Install, import (and use?) deepl-node in your code
  3. Build it

Expected behavior The warning not to appear by refactoring your code

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Arc
  • Version: 1.39.0

WarningImHack3r avatar Apr 20 '24 18:04 WarningImHack3r

Hi, could you provide more detailed steps how to reproduce this? I just did the following (with node v18.18.2 and deepl-node v1.13.0) in a new directory:

  • npm create svelte@latest test-app
  • cd test-app
  • npm add deepl-node
  • npm install
  • Edit src/app.d.ts to look like the following
import * as deepl from 'deepl-node';


// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
	namespace App {
		// interface Error {}
		// interface Locals {}
		// interface PageData {}
		// interface PageState {}
		// interface Platform {}
	}
}

async function translate() {
	let t = deepl.Translator('auth_key');
	let result = await t.translateText('sample text', null, 'de');
	return result;
}

export {};
  • npm run dev

And I dont get this warning.

JanEbbing avatar Apr 22 '24 08:04 JanEbbing

Hi, I don't have access to my code right now, but it didn't show up on a dev server, only on a full prod build (npm run build). It's pretty easy to spot though, the index.js file imports stuff from parsing.js, and parsing.js also imports stuff from index.js, thus creating a circular import. It's not a big problem as you only import specific functions from one another but it's just a "bad practice", hence the warning

WarningImHack3r avatar Apr 22 '24 08:04 WarningImHack3r

Ah sorry, I didn't get that it's just a warning. I agree, we should move a bunch of definitions into types.ts. I'll take a look.

JanEbbing avatar Apr 22 '24 08:04 JanEbbing

Sorry about the wording, thanks!

WarningImHack3r avatar Apr 22 '24 08:04 WarningImHack3r