svelte-progressbar icon indicating copy to clipboard operation
svelte-progressbar copied to clipboard

Could not load index.mjs for typescript project

Open kneumei opened this issue 1 year ago • 5 comments

Getting this error when doing npm build:

Could not load C:<Path-To-My-App>\node_modules@okrad\svelte-progressbar\index.mjs (imported by src/App.svelte): ENOENT: no such file or directory, open 'C:<Path-To-My-App>\node_modules@okrad\svelte-progressbar\index.mjs'

To reproduce:

  1. npx degit sveltejs/template app
  2. node scripts/setupTypeScript.js
  3. npm i
  4. npm i @okrad/svelte-progressbar

Modify main.ts

import App from './App.svelte';

const app = new App({
	target: document.body,
	props: {
		name: 'world',
		series: [{ perc: 20 }, { perc: 42 }]
	}
});

export default app;

Modify App.svelte

<script lang="ts">
  import type { Series } from "@okrad/svelte-progressbar";
  import ProgressBar from "@okrad/svelte-progressbar";
  export let name: string;
  export let series: Series[] = [];
</script>

<main>
  <h1>Hello {name}!</h1>
  <p>
    Visit the <a href="https://svelte.dev/tutorial">Svelte tutorial</a> to learn
    how to build Svelte apps.
  </p>
  <ProgressBar {series} />
</main>

Finally run npm run build

kneumei avatar Mar 16 '23 21:03 kneumei

I'm also seeing this, but I think this is just a typescript definition issue that I can ignore.

Argument of type 'typeof ProgressBar' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent'.
  Type 'ProgressBar' is missing the following properties from type 'ATypedSvelteComponent': $$events_def, $$slot_def, $on

Possible causes:
- You use the instance type of a component where you should use the constructor type
- Type definitions are missing for this Svelte Component. If you are using Svelte 3.31+, use SvelteComponentTyped to add a definition:
  import type { SvelteComponentTyped } from "svelte";
  class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}ts(2345)

kneumei avatar Mar 16 '23 21:03 kneumei

Downgrading to 1.11.3 looks like it fixes the issue. In this version I see index.js and index.mjs in the node_modules folder

image

In the 2.0.0 version, I don't see these files

image

kneumei avatar Mar 16 '23 21:03 kneumei

Hi @kneumei, thank you for reporting! Can you try out the newest release (2.0.1)?

okrad avatar Mar 21 '23 09:03 okrad

Thanks @okrad

Looks like the build time errors and warnings are resolved, but now I'm getting a runtime error. I'm not really familiar enough with svelte to diagnose much...but I am running this as I described in my previous post: I just modified the hello world svelte project to include progress bar

image

kneumei avatar Mar 21 '23 11:03 kneumei

@kneumei, it should be fixed now, with the added advantage that the library is now converted to Sveltekit!

The disadvantage is that the library doesn't get bundled by default, In case it is needed, the bundled version can get created by running the npm run bundle command.

Can you try it out?

okrad avatar Mar 22 '23 22:03 okrad