Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite fails on module specifiers when importing Plugin class #3221

Closed
Laurelin opened this issue May 20, 2023 · 3 comments
Closed

Vite fails on module specifiers when importing Plugin class #3221

Laurelin opened this issue May 20, 2023 · 3 comments
Labels
bug build Build or distribution file related enhancement

Comments

@Laurelin
Copy link

Laurelin commented May 20, 2023

Description

I'm attempting to build a plugin for my app using Typescript. It looks great in my code editor, but it fails on vite:import-analysis because the base class for plugins is not included in the module specifiers. I'm using Nuxt 3.

I can see and click into the Plugin class from intellisense and node_modules. It's there, but vite fails it.

Steps to check or reproduce

import Plugin from 'billboard.js/src/plugin/Plugin'
import _ from 'lodash'

class myClass extends Plugin {
...
}

run the nuxt dev command in terminal

ERROR Internal server error: Missing "./src/plugin/Plugin" specifier in "billboard.js" package
Plugin: vite:import-analysis

@netil
Copy link
Member

netil commented May 24, 2023

Hi @Laurelin, this is related to the build/bundling environment you're working on.
From the dist package, src contains the source code and Plugin class is one of them. It provides .ts and .js extensions files.

I'm not sure the cause, but from the err message the vite:import-analysis failing resolving Plugin class file.
Try specifying extension on import statement.

import Plugin from 'billboard.js/src/plugin/Plugin.js';  // or Plugin.ts

If you can provide reproducible example will help to dig in more.

@Laurelin
Copy link
Author

Hello! That import line fails to resolve in vite.

It's because your package.json exports don't specify it :

"exports": {
		".": {
			"types": "./types/index.d.ts",
			"import": "./dist-esm/billboard.js",
			"require": "./dist/billboard.pkgd.js"
		},
		"./dist/plugin/*": {
			"types": "./types/plugin/*.d.ts",
			"import": "./dist-esm/plugin/*.js",
			"require": "./dist/plugin/pkgd/*.js"
		},
		"./dist/*": "./dist/*"
	}

none of those refer to a /src/plugin.

When add this to the exports:

"./src/plugin/*":{
      "import": "./src/plugin/*.js"
    },

Vite resolves the plugin fine. I'm not quite sure on etiquette here; I can fork and make a PR for this. I'm also not sure if this does something that you all don't want happening. In particular, I notice that all the types on the Plugins are 'any' because ChartInternal is private(ish?) and none of the types it uses are exported.

So while I know that this.$$ in a plugin is a ChartInternal object, I have to mark it as an 'any' and can't rely on typescript hints to see what I can do with it. Are these things supposed to be public? Am I supposed to be developing plugins as a fork of billboard.js itself?

@netil
Copy link
Member

netil commented Jun 8, 2023

@Laurelin, thanks for the comment.

There're no needs from the user perspective to import each files from /src, except the Plugin.js.
So, IMO pointing Plugin.js will be okay in general.

"exports": {
 	...  
 	"./src/Plugin/Plugin.js": "./src/Plugin/Plugin.js"
},

Can you make a PR for this?

@netil netil added enhancement build Build or distribution file related labels Jun 8, 2023
netil pushed a commit to netil/billboard.js that referenced this issue Jun 14, 2023
Fix Plugin class to be imported from the npm package module.

Ref naver#3221
@netil netil closed this as completed in 24c0976 Jun 14, 2023
@netil netil added the bug label Jun 14, 2023
github-actions bot pushed a commit that referenced this issue Jun 15, 2023
# [3.9.0-next.1](3.8.2...3.9.0-next.1) (2023-06-15)

### Bug Fixes

* **export:** Fix Plugin class import ([24c0976](24c0976)), closes [#3221](#3221)
* **shape:** Fix shape rendering issue on Windows ([cf1b484](cf1b484)), closes [#3222](#3222)
* **tooltip:** Fix tooltip overflow when right side edge is hovered ([9ce900d](9ce900d)), closes [#3254](#3254)

### Features

* **arc:** Intent to ship arc.needle ([04e90aa](04e90aa)), closes [#3205](#3205)
* **data:** Intent to ship data.labels.position function ([59be3ec](59be3ec)), closes [#3237](#3237)
* **module:** Support dual CJS/ESM package ([437c007](437c007)), closes [#2202](#2202)
* **plugin:** Intent to ship TableView plugin ([215b611](215b611)), closes [#1873](#1873)
* **theme:** Intent to ship dark theme ([252a28e](252a28e)), closes [#3229](#3229)
github-actions bot pushed a commit that referenced this issue Jul 3, 2023
# [3.9.0](3.8.2...3.9.0) (2023-07-03)

### Bug Fixes

* **export:** Fix Plugin class import ([24c0976](24c0976)), closes [#3221](#3221)
* **shape:** Fix shape rendering issue on Windows ([cf1b484](cf1b484)), closes [#3222](#3222)
* **tooltip:** Fix tooltip overflow when right side edge is hovered ([9ce900d](9ce900d)), closes [#3254](#3254)

### Features

* **arc:** Intent to ship arc.needle ([04e90aa](04e90aa)), closes [#3205](#3205)
* **bar:** Intent to ship bar.front ([f7e0d80](f7e0d80)), closes [#2965](#2965)
* **data:** Intent to ship data.labels.position function ([59be3ec](59be3ec)), closes [#3237](#3237)
* **legend:** Intent to ship legend.item.interaction.dblclick ([18f5c4a](18f5c4a)), closes [#1404](#1404)
* **legend:** Intent to ship legent.item.interaction ([af87d10](af87d10)), closes [#1598](#1598)
* **point:** Enhance point.sensitivity ([a537201](a537201)), closes [#2568](#2568)
* **theme:** Intent to ship dark theme ([252a28e](252a28e)), closes [#3229](#3229)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug build Build or distribution file related enhancement
Projects
None yet
Development

No branches or pull requests

2 participants