After upgrading my project from Angular 11 to Angular 12, I encountered errors while using the ng update command. Instead of troubleshooting further, I decided to take a more manual approach.
I started by creating a brand new Angular 12 project, re-adding all the necessary dependencies, and then replacing the src folder from my old Angular 11 project. Since the config files in the Angular 11 project had default values, I assumed that sticking with the defaults in Angular 12 would work smoothly.
However, my optimism quickly faded as I saw the build logs filled with error TS2307 related to local files.
Despite confirming that the file was indeed present in the folder, the error persisted:
Error: src/app/components/open-orders/open-orders.component.ts:2:23 - error TS2307: Cannot find module 'src/app/data/Order' or its corresponding type declarations.
tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
}
}
This is the open-orders.component.ts file:
import { Component, OnInit } from '@angular/core';
import { Order } from 'src/app/data/Order';
import { CloudService } from 'src/app/services/cloud.service';
The same TS2307 error persisted for both local imports.
Even after attempting to use relative paths, the issue remained:
import { Component, OnInit } from '@angular/core';
import { Order } from '../../data/Order';
import { CloudService } from '../../services/cloud.service';
Despite trying various solutions found online in the tsconfig.json and angular.json files, none seemed to solve the TS2307 problem at hand.
Could this be specifically related to Angular 12? Any assistance in resolving this issue would be greatly appreciated.