admin管理员组

文章数量:1426066

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:

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],
    ponent: 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?

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:

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],
    ponent: 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?

Share Improve this question edited Jan 22, 2024 at 20:45 Ohgodwhy 50.8k11 gold badges85 silver badges113 bronze badges asked Jan 22, 2024 at 19:59 ExoorExoor 772 silver badges7 bronze badges 2
  • Can you check your base href in your index.html – Matthieu Riegler 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'; – Eliseo Commented Jan 23, 2024 at 7:27
Add a ment  | 

1 Answer 1

Reset to default 6

I have the same problem and find a solution here

https://github./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 the angular.json like this:

angular.json 
"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.

本文标签: