Alias route for `src` in Ionic 3

I have set up a custom webpack configuration for Ionic 3 in order to use src as a path alias (meaning I can import from src/module/file):

resolve: {
  alias: {
    'src': path.resolve('./src')
  }
}

However, after updating to Ionic app scripts @ 3, I encountered an error stating

Cannot find module src/module/file
when trying to serve or build.

I have come across methods for creating path aliases to import from directories within src (such as app, pages, etc.) that involve modifying the Webpack resolve alias and updating the baseUrl in tsconfig.json. For instance:

https://medium.com/@siddhartha.ng/ionic-3-import-using-aliases-2aa260d6fab3

Nevertheless, my goal is to be able to import directly from src rather than a subdirectory of src. Is there a way to achieve this by adjusting my webpack or TypeScript configuration?

Answer №1

With the latest updates to Ionic 3, the webpack configuration now includes two main properties at the top level: dev and prop, each corresponding to different webpack configurations.

To adapt to this change, you will need to update both the dev and prod properties and export the entire object from the webpack configuration. There are multiple ways to achieve this, but one example is:

const config = require('@ionic/app-scripts/config/webpack.config.js');

config[process.env.IONIC_ENV].resolve.alias = { src: path.resolve('./src') };

module.exports = config; // You can also choose to export a function that returns this

Remember that it is essential to export the complete object with both configurations included. Using module.exports = config[env] alone will not suffice.

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

Using p5.js with TypeScript and Webpack is not supported

I'm currently working on a library project that involves utilizing p5.js. Specifications Here is a snippet of my Webpack configuration: const path = require('path'); module.exports = { entry: './start.ts', output: { ...

The Angular4 service being utilized is not defined within the public function

Currently, I am facing an issue with my services setup. I have two services in place - the first service is responsible for the map function within the http CRUD Function, while the second service is supposed to perform a task that is provided by the first ...

When utilizing RxJS, the process of filtering Observable data may not function as expected if the filtering is carried out within a separate function rather than directly within the subscribe

While attempting to filter data from an external source using the RxJS filter on Observables, I encountered an issue where all records were returned instead of just the ones meeting the filtering criteria. This problem occurred when the code was within a l ...

The element of type 'OverridableComponent<LinkTypeMap<{}, "a">>' cannot be assigned to a 'ReactNode'

I'm currently working on a project where there's a component named ListItemTextStyle. Within that component, the prop type is defined as follows: import { LinkProps, ListItemButtonProps, } from '@mui/material'; type IProps = LinkP ...

Step-by-step guide on implementing virtual scroll feature with ngFor Directive in Ionic 2

I am working on a project where I need to repeat a card multiple times using ngFor. Since the number of cards will vary each time the page loads, I want to use virtual scrolling to handle any potential overflow. However, I have been struggling to get it ...

The dropdown will close automatically when the user clicks outside of it

My dropdown setup requires it to close when the user clicks outside of it. <div [class.open]="qtydropdownOpened"> <button (click)="qtydropdownOpened = !qtydropdownOpened" type="button" data-toggle="dropdown" aria-haspopup="true" [att ...

NodeJS/express: server became unresponsive after running for some time

Initially, my service using express and webpack ran smoothly. However, I started encountering an issue where the server would hang with no message code being received, as shown in the server message screenshot (server message screenshot). This problem kept ...

Theme not being rendered properly following the generation of a dynamic component in Angular

I am currently working on an Angular 9 application and I have successfully implemented a print functionality by creating components dynamically. However, I have encountered an issue where the CSS properties defined in the print-report.component.scss file a ...

Arrange a collection of objects by two criteria: the end time, followed by the status in accordance with the specified array order if the end times are equal

Is this the best method to arrange data by using infinity? I gave it a try but it doesn't quite meet my requirements. data = [{ "status": "Accepted", "endTime": "" }, { "status": "New", ...

What is the rationale behind TypeScript's decision to implement two checks for its optional chaining and null-coalescing operators during compilation?

What is the reason behind the way the TypeScript compiler translates its optional chaining and null-coalescing operators, found here, from: // x?.y x === null || x === void 0 ? void 0 : x.y; // x ?? y x !== null && x !== void 0 ? x : y as opposed ...

When trying to create a new project using `ng new project`, the path specified was not

I'm attempting to start an angular 4 project using angular-cli on my Windows 10 operating system. I followed the instructions outlined at https://www.npmjs.com/package/@angular/cli. Currently, I am running node - 7.6.0 and npm - 5.1.0. Every time I ...

Utilizing directives while initiating dynamic components

I've been exploring the capabilities of dynamically creating components using the ComponentFactoryResolver. const factory = this.componentFactoryResolver.resolveComponentFactory(FooComponent); const component = this.templateRoot. ...

Is there a way to prevent vertical scrolling during left swipes in Ionic?

I am in the process of creating an Ionic mobile application, where the main view consists of a vertical list of cards. I would like each card to be "swipable" in a similar fashion to Google Now cards. I have begun implementing this functionality: $scope. ...

Experiencing issues with the functionality of getServerSideProps in my project

I'm scratching my head over why server-side props aren't working for me in nextjs (v12). I'm utilizing getServerSideProps inside pages/details/index.tsx. export const getServerSideProps = async (context: any) => { const name = context.q ...

An improved method for implementing conditional statements in Angular

After researching online, I came across some discussions about using if else logic in Angular. Although I was able to achieve the desired outcome, I am curious if there is a more efficient or alternative way to implement if else statements in Angular. In ...

`Incorporate concurrent network requests in React for improved performance`

I am looking to fetch time-series data from a rest service, and currently my implementation looks like this async function getTimeSeriesQuery(i) { // Demonstrating the usage of gql appollo.query(getChunkQueryOptions(i)) } var promises = [] for(var i ...

The bamboo construction falters as webpack is unable to locate the node_modules

After setting up my Angular project with webpack in version 1.7, everything runs smoothly locally when I execute the npm run build task to launch webpack. However, I encountered an issue when trying to set up a plan for continuous integration using bamboo ...

Guide on positioning a span element to the left using the margin auto property in CSS for Angular 4

Having trouble with moving numbers highlighted to the left with names in CSS. I've tried using flex direction and margin auto but can't achieve the desired result. Here is my HTML code: <section class="favorites"> <div class="category" ...

Encountering issues with running npm install on a local Angular project

Whenever I try to execute npm install on my local Angular project, I encounter the following errors: C:\Projects\Angular>npm install npm ERR! code ENOENT npm ERR! syscall spawn git npm ERR! path git npm ERR! errno ENOENT npm ERR! enoent Error ...

There was an error during module build process: ReferenceError occurred due to an unrecognized plugin "import" specified in "base" at position 0

I have encountered an error while working on my ReactJS project using create-react-app. The error arose after I added and removed a package called "react-rte". Now, every time I try to start my project, I get the following error: Error in ./src/index.js Mo ...