3

I’m working on an Angular 17 application and I’m trying to create a route with the path /admin/xxxx. However, when I try to access the route http://localhost:4200/admin/dashboard, I get the following error: enter image description here

20:44:30 [vite] Pre-transform error: Failed to load url /admin/polyfills.js (resolved id: /admin/polyfills.js). Does the file exist? 20:44:30 [vite] Pre-transform error: Failed to load url /admin/main.js (resolved id: /admin/main.js). Does the file exist?

Here’s what my code looks like: ps : when i use path : '' it works fine with routes http://localhost:4200/dashboard

{
    path: 'admin',
    // canActivate: [AuthGuard],
    // canActivateChild: [AdminGuard],
    component: LayoutComponent,
    data: {
      layout: 'admin',
    },
    children: [
      {
        path: 'users',
        loadChildren: () =>
          import('./modules/users/users.module').then((m) => m.UsersModule),
      },
      {
        path: 'dashboard',
        loadChildren: () =>
          import('./modules/dashboard/dashboard.module').then(
            (m) => m.DashboardModule
          ),
      },
      {
        path: '',
        redirectTo: 'dashboard',
        pathMatch: 'full',
      },
    ],
  },

Can anyone help me figure out what’s causing this error and how to fix it?

2
  • Can you check your base href in your index.html Commented Jan 22, 2024 at 23:12
  • 1
    Check your angular.json and look for polyfills in projects-->your-app-->architect-->build-->options. If you neend't polyfill, remove the line. Generally you use polyfill to import 'zone.js' (but you can import in anyplace diferent) or '@angular/localize/init'; Commented Jan 23, 2024 at 7:27

1 Answer 1

7

I have the same problem and find a solution here

https://github.com/angular/angular-cli/issues/26897

It is an issue that was corrected in the code, but I updated all my package and still have the problem.

In the url someone suggest to use "externalDependencies":[""], in the options of angular.json.

In angular.json:

{
    "projects": {
        "Your Project": {
            "architect": {
                "build": {
                    "builder": "@angular-devkit/build-angular:application",
                    "options": {
                        "externalDependencies":[""],

and it worked to me. I hope it can help, and I suggest to visit the url.

Sign up to request clarification or add additional context in comments.

4 Comments

Do you know the work around for monorepo projects? It doesn't have angular.json. It has project.json
Sorry, I don´t. I find the solution in the URI shared. Sorry.
Thanks for your reply. I figured that out. The solution for project.json is very similar to angular.json. But it doesn't solve the problem completely. There are still a lot of vitejs requests
Same problem with Angular and Angular CLI 20.2.2, and this solution also worked for me. Very odd, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.