What strategies can be employed to manage three conflicting versions of a single library within a Vite project?

I am currently facing a unique challenge in my web app development process. Specifically, I am using the Vite framework with the svelte-ts template setup to build an application that integrates different libraries for WebXR based augmented reality. The goal is to switch between these libraries easily to compare their performance on different pages or Svelte components tied to various routes.

The dilemma arises from the fact that each of these libraries relies on different versions of THREE.js:

  • The first option is the latest version of THREE.js.
  • The second option is A-Frame, which utilizes a forked version of THREE known as "super-three" but shares the same global context as THREE.
  • The third option is ModelViewer, which uses an older version of THREE.

Attempting to install all these libraries into the same Node.js modules folder via npm results in conflicts due to their respective dependencies. Using options like "--legacy-peer-deps" or "--force" during installation proves ineffective since it does not allow me to enforce the use of a specific version (and super-three poses further complications).

Implementing import aliases is not feasible, as A-Frame and ModelViewer require direct access to THREE without any modifications internally. Moreover, there is shared code crucial for the general app and all three WebXR components to utilize. Although I attempted a monorepo approach where each WebXR component has its own submodule with a separate node_modules folder, everything ended up being installed at the root level, leading to the same conflicts. It is imperative to maintain a single deployable app.

- / (root level)
   - node_modules/
   - packages/
     - three/
       - src/
       - package.json
       - ...
     - aframe/
       - src/
       - package.json
       - ...
     - model-viewer/
       - src/
       - package.json
       - ...
   - shared
     - src
     - package.json
     - ...remaining vite, typescript and svelte stuff

Exploring the possibility of developing the entire app in Svelte, while having the three WebXR pages as static HTML pages linked separately with dependencies loaded through <script></script> tags, also presented challenges in accessing the shared code. Perhaps compiling all shared code into a standard shared.js file that both Svelte components and independent pages can utilize would be a viable solution?

Dynamic imports were considered, but they still necessitate the prior installation of dependencies in the node_modules folder, leading to conflicts. How can I resolve this issue effectively to ensure a unified deployable app?

Answer №1

If you're looking to tackle the challenge of handling multiple versions of three.js without conflicts, my suggestion would be to create four separate Vite projects and implement single-spa in ES modules using my plugin, vite-plugin-single-spa. Each project will serve as a single-spa micro-frontend project.

The fourth project will act as the root project for single-spa, loading the appropriate micro-frontend based on the user's choice.

This approach should meet your requirements up to this point, with the exception of the "one deployable app" condition.

If dealing with 4 deployments is acceptable to you, then that's all you need to do. Simply set up 4 distinct deployments following single-spa's architecture.

If handling 4 deployments is not ideal, then consider consolidating into a single deployment. As you may already be aware, Vite generates static websites (static files) as output. Build each project separately and combine the build results into a single server deployment - problem solved!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error in Svelte/Typescript: Encounter of an "unexpected token" while declaring a type

Having a Svelte application with TypeScript enabled, I encountered an issue while trying to run it: [!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript) src\api.ts (4:7) 2: 3: export default class API { 4: ...

Prevent empty comments in Vue.js

Typically, Vue.js will insert a comment placeholder when hiding an element using v-if. Vue file: <div v-if="true">Hello</div> <div v-if="false">world</div> Output: <div v-if="true">Hello</div ...

Image Switching Hover Bug

HTML: <div id="logo"></div> <div id="coming-soon"></div> JavaScript: $(document).ready(function(){ $("#logo").hover( function(){ $("#logo").fadeTo(300, 0); $("#coming-soon").fadeTo(300, 1.0 ...

Capturing mouse clicks in Javascript: a guide to detecting when the mouse moves between mousedown and mouseup events

I have been working on a website that features a scrolling JavaScript timeline, inspired by the code found in this tutorial. You can check out the demo for this tutorial here. One issue I've encountered is when a user attempts to drag the timeline an ...

What is the best way to iterate through an array of objects in React and JavaScript, adding a new property to each object in order to generate a new array

Greetings, I am currently dealing with an array of objects structured as follows: const arr_obj = [ { children: [{}], type: "type1", updated: "somevalue", }, { children: [{}], type: ...

Is it possible to adjust the timezone settings on my GraphQL timestamp data?

I've come across a lot of helpful information regarding the usage of Date() and timezones, but something seems to be off. In my GraphQL setup (sourcing from Sanity), I have configured it to use formatString in this manner: export default function Minu ...

Ways to resolve the responseJSON showing {error: "invalid_request", error_description: "Code parameter is missing"}

My current issue involves uploading files to Google Drive from my Vuejs and JavaScript web application. The request I send is returning an error. Upon checking, I noticed that the variable code is null, and even the variable window.location.search is empty ...

Determining Asynchrony in Node.js Through Programming

Is there a way to assess if a function can be executed asynchronously without requiring a callback? I am currently working with Node.js on the Intel Edison platform and utilizing mraa. The native C++ functions like i2c.readReg(address) do not have provisi ...

ClickAwayListener doesn't function correctly when used in conjunction with Collapse or Fade animations

Currently, I am working on implementing a notifications area on my website. The idea is to display a notification icon, and once the user clicks on it, a list of notifications will be shown. For reference, you can view the code in this codesandbox I have ...

Tips for creating a Carousel with more than three images using Bootstrap

Recently, I attempted to enhance my Carousel in Bootstrap by adding more images. Initially, I inserted the code snippet below within the ordered list with the class "carousel-indicators." <li data-target="#carouselExampleCaptions" data-slide-to=" ...

Tips for getting information from a GET/POST response message with superagent

I'm currently utilizing Node.js and Superagent for testing my server implementation. I have successfully sent a Superagent GET request and received a positive response with the code provided below. My goal is to extract and log only the "id" value fro ...

Dynamic JavaScript Animation

Check out this code snippet I currently have. Notice how the text seems to jump when rerun? Give it a try and see for yourself. The big question is: How can this be fixed? $("#aboutUsText").delay(1000).fadeOut(1000) $("#aboutUsText").attr("MyState", "1") ...

The element is implicitly classified as an 'any' type due to the index expression not being of type 'number'

Encountering a specific error, I am aware of what the code signifies but unsure about the correct interface format: An error is occurring due to an 'any' type being implicitly assigned as the index expression is not of type 'number'. ...

Encountered an issue when attempting to establish a connection with the REST

I am encountering an issue with connecting to a web service deployed on an Apache server using Jersey. The error message I receive is: Failed to load http://192.168.1.200:8199/CheckinnWeb/webapi/myresource/query: No 'Access-Control-Allow-Origin' ...

Select a random class from an array of classes in JavaScript

I have a collection of Classes: possibleEnemies: [ Slime, (currently only one available) ], I am trying to randomly pick one of them and assign it to a variable like this (all classes are derived from the Enemy class): this.enemy = new this.possibleEn ...

Exploring the intersection of onBeforeUnload and node.js

I just started learning about node.js. I'm curious if onbeforeunload can be used in node.js. If so, will the "no script" plugin for Firefox block scripts created by node.js? I want to inform my visitors with a message before they leave the page withou ...

Modify the placeholder HTML once a username has been submitted

In order to maximize efficiency, I have included an input box with a placeholder that reads: <input id="username-search" placeholder="explore another user's work"> Once the username is entered, I want to modify the placeholder text to somethin ...

Ensuring the Persistence of Column State in Material-UI DataGrid/DataGridPro when Adjusting Visibility Using Column Toolbar

We have integrated MUI DataGrid into our React project. Currently, I am exploring options to save the state of columns after toggling their visibility using the DataGrid toolbar column menu. After each re-render, the column setup returns to its default st ...

Utilizing state in React for CRUD operations is a fundamental practice

Currently, I am developing a React application using altjs as my Flux implementation. I have encountered an issue where when attempting to create or delete an item from the front end, regardless of the parameter passed to the function, the entire state is ...

The RSS feed is stretching beyond the limits of the table's height

Seeking assistance to adjust the height of an RSS feed widget on my website. The widget is from RSS Dog and I do not have access to the style.css file as it is hosted externally. Despite trying to modify the JavaScript code provided by RSS Dog to set the h ...