Guide on implementing a git submodule in a typescript project containing typescript code

In my current VueJS project, I am implementing different color schemes and other customized features based on an environment variable. These configurations are stored in a separate repository that has been added as a submodule within the project structure:

  • my-project
    • the-submodule
    • node_modules
    • public
    • src

To ensure functionality, I have included the following code snippet in my vue.config.js:

module.exports = {
  chainWebpack: config => {
    config.resolve.alias
      .set('@theme', path.resolve('the-submodule/' + process.env.VUE_APP_THEME))
  },
...

This configuration is then used within various files, such as plugins/vuetify.ts:

import Vue from 'vue'
import Vuetify from 'vuetify/lib/framework'
import colors from '@theme/colors'

Vue.use(Vuetify)

export default new Vuetify({
  theme: {
    themes: {
      light: {
        ...colors
      }
    }
  }
})

Similarly, it is utilized in router/index.ts:

import texts from '@theme/texts'

...

router.afterEach((to) => {
  Vue.nextTick(() => {
    document.title = to.meta.title ? `${texts.appName} | ${to.meta.title}` : texts.appName
  })
})

Although the code compiles and functions properly, compilation errors persist:

ERROR in /Users/sme/projects/aedifion-frontend/src/plugins/vuetify.ts(4,20):
4:20 Cannot find module '@theme/colors' or its corresponding type declarations.
    2 | import Vue from 'vue'
    3 | import Vuetify from 'vuetify/lib/framework'
  > 4 | import colors from '@theme/colors'
      |                    ^
    5 | 
    6 | Vue.use(Vuetify)
    7 | 
ERROR in /Users/sme/projects/aedifion-frontend/src/router/index.ts(12,19):
12:19 Cannot find module '@theme/texts' or its corresponding type declarations.
  > 12 | import texts from '@theme/texts'
       |                   ^

The theme files are structured as follows:

the-submodule/some-theme/colors.ts
:

import { Colors } from '../types'

export default {
  accent: '#288946',
  error: '#e60046',
  info: '#969196',
  primary: '#007982',
  secondary: '#96BE0D',
  success: '#a0af69',
  warning: '#fab450'
} as Colors

the-submodule/some-theme/texts.ts
:

import { Texts } from '../types'

export default {
  appName: 'MyApp'
} as Texts

the-submodule/types.ts:

export interface Colors {
  accent: string;
  error: string;
  info: string;
  primary: string;
  secondary: string;
  success: string;
  warning: string;
}

export interface Texts {
  appName: string;
}

I have also created custom versions of .d.ts files within the-submodule for these types.

I have attempted various solutions to resolve these errors without success. How can I address these compilation issues effectively?

UPDATE:

A workaround that works involves explicitly mapping paths in the tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "src/*"
      ],
      "@theme/*": [
        "the-submodule/some-theme/*"
      ]
    },

Therefore, the question remains: How can I configure path mappings in the tsconfig-json without needing to specify each subfolder like some-theme?

Answer №1

Have you considered placing the submodule folder within the rootDirs section of the tsconfig.json file?

"compilerOptions": {
     "rootDirs": ["src/","*submodule folder*"],   /* List of root folders whose combined content makes up the project's structure at runtime. */
    }

source: https://www.typescriptlang.org/tsconfig#rootDirs

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

Exploring the Dynamic Duo: Laravel Echo and JQuery

After including Echo in Vue.js' resources/assets/js/bootstrap.js, one of my components is throwing an error The error message states: "Error in mounted hook: 'TypeError: $ is not a function'" When I remove the Echo import, everything run ...

A guide on efficiently storing and retrieving a webpage containing two angular2 components using local storage

I've been attempting to store and retrieve a page containing two angular2 components from local storage using the following code, but the component CSS is not being applied. Here is the code I'm using to save: localStorage.setItem('pageCon ...

Updating the font color of Materializecss select options

I have encountered an issue while using Materaliizecss select in two separate vue.js components. In one component, I want the select text color to be white, while in the other component, I want it to be black. In the first component's style, I manage ...

Upon the second click, the addEventListener function is triggered

When using the window.addEventListener, I am encountering an issue where it only triggers on the second click. This is happening after I initially click on the li element to view the task information, and then click on the delete button which fires the eve ...

Vue.js quasar q-input component not triggering event upon input modification

I have a scenario with two components - ModalName.vue as the child component and AddTask.vue as the parent component. In ModalName.vue (child component), if I emit an event on change of input using HTML <input /> element to update the state in the ...

Discovering an object by its id in vue-router parameters and subsequently sending its attributes to a template within Vue

In my ContactDetails component, I am fetching data from the vuex state and storing it in a contacts array. Then, within a computed property, I am attempting to find and return an object based on the id prop passed from the router params. Here is the code ...

How can I set the first matched value in a Vue (Element UI) dropdown as the default selection?

Framework used: Vue and Element UI Mission: The goal is to have the first matched value displayed by default. Issue: When selecting Texas from the common states, it displays Texas from all states in the dropdown when opened. Both should be selected as th ...

Which module system is best suited for your tsconfig: commonjs, umd, or es6?

Which module should be specified in tsconfig, commonjs or es6? What factors should be considered when deciding? The output module needs to work on both the client and back ends. ...

Saving search results using AJAX in Vue and Laravel's database

I am working towards creating a feature with two input fields where users can type in the three-letter code of an airport. Through AJAX, a query will run to verify if the airport exists in the database. If it does, the name of the airport will be displayed ...

An issue arises when trying to showcase necessary data within vue.js templates

I'm having an issue with displaying a specific value based on an onclick event. The value is taken from an object in the bookData array: this.bookData.push( { avalable: true, titles: [title, id], author ...

Using Typescript and webpack to detect variables that are defined in the browser but not in Node environment

My goal is to create a package that can be used on both servers and clients with minimal modifications required. Some libraries are available in Node but not in a browser, while others are accessible in a browser but not in Node. For instance, when utili ...

Topic: Creating specific return types for methods that are chained and reusable

Here is a code snippet I am currently working on: const mixed = { validations: [] as any[], formattings: [] as any[], exceptions: [] as any[], required(message?: string) { this.validations.push({ name: 'required', message: ...

Tips for reducing a discriminated union by using the key value of a Record

I am working with a union type that has a discriminator property called "type". I then define a Record<> where the keys are the "type" property values. How can I specify the second generic parameter of the Record (Record< , this param>) so tha ...

Secure paths with [local] section of the URL

When it comes to managing app routes for an i18n application, I initially relied on reading the request headers (cookies and accept-language) to determine the locale. The experimental typedRoutes feature was working perfectly fine in this setup. However, I ...

What is the process for updating input data after loading data from onSSR?

I've been encountering an issue with loading my shipping data from the server (onSSR) and updating it to my input form. Despite placing my code within onSSR as follows, the update does not occur: onSSR(async () => { await load(); await ...

How can I efficiently update Vue data externally?

const app = createApp({ data() { return { unique_id: 0 } } }) I implemented an autocomplete feature on a specific input field. My goal is to send the chosen id to a Vue application when a label is selected. onSelectItem: ({label, value}) ...

Angular2's asynchronous data binding is still lagging even after the data has been successfully loaded

I have integrated Firebase with Angular2 to retrieve an object. import { Component, OnInit } from '@angular/core'; import { AngularFire, FirebaseObjectObservable } from 'angularfire2'; import { ActivatedRoute, Params } from '@angu ...

How can you access the input value from load dash's debounce function in a Vue.js application?

Is there a way to capture the input entered during the @typing event of the b-autocomplete component in Buefy? During the @typing event, the debounce method is called with specific parameters as shown below- <b-field label="Location"> ...

Tips on showing a stub component in Vue when the original component is not found

Seeking a way to handle the scenario where a component is not found, such as: { template: '<some-unknown-component></some-unknown-component>' } When this happens, Vue issues a warning: unknown custom element: <some-unknown-comp ...

Exciting interactive data visualization with TypeScript/Angular utilizing Google's dynamic

Looking to add some dynamism here. Anyone with experience in Angular and Typescript willing to lend a hand? I'm still new to these technologies. Here's the code snippet in question: Currently, I'm manually adding row columns. Is there a wa ...