illustspace / aframe-typescript-class-components

A simple tool for writing Aframe components as TypeScript classes.
https://www.npmjs.com/package/aframe-typescript-class-components
MIT License
12 stars 1 forks source link

A node type is already registered #6

Closed krsbx closed 2 years ago

krsbx commented 2 years ago

image

is it registering the component twice? even though i only import the file once

will-wow commented 2 years ago

@krsbx that's odd! even if you import a file with an @component decorator multiple times, the component should only be registered once. Can you share the component definition that's throwing this error?

And is it possible that you've either got two components with the same a-node name, or are using both the @component("a-node") decorator, and an AFRAME.registerComponent("a-node" call?

krsbx commented 2 years ago

@will-wow i made the component in here and import the component in here and this how i use the component

will-wow commented 2 years ago

@krsbx ah-hah! I cloned your repo, and I think the issue is that this library is relying on the aframe node_module, but your index.html is also doing <script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>, so you end up with two copies of Aframe, which are conflicting with each other.

One solution is to remove the <script> tag and just rely on the NPM dependency, which seems to work without any errors.

If you want to keep pulling aframe in as a script tag instead, you can also add externals: { aframe: 'AFRAME' } to your webpack config (that's how we're doing it on the project I'm using this on right now). It looks like you're using Vite, so you may need to use something like https://github.com/lceric/vite-plugin-resolve-externals or https://github.com/crcong/vite-plugin-externals (I'm haven't used Vite recently so I'm not up-to-date on the best libraries) if you go down the externals path.

Hope that helps, and I'm going to add a note in the docs about this!