Angular从8升级到9后,懒加载模块警告。

问题描述 投票:0回答:2

Angular更新后,所有懒加载的模块都返回警告。

Error: [path/to/module/module-name.ts] is missing from the TypeScript
compilation. Please make sure it is in your tsconfig via the 'files'
or 'include' property.

我的函数返回模块数组。

export function manifests(prefix = '') {
    return [
        {
            loadChildren: () => import(prefix + '/path/to/a.module').then(m => m.AModule),
            path: 'a',
        },
        {
            loadChildren: () => import(prefix + '/path/to/b.module').then(m => m.BModule),
            path: 'b',
        },
    ]
}

如果我把这个函数换成静态数组,一切都会好起来的。为什么呢?

我的 tsconfig.app.json:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts",
    "src/zone-flags.ts",
  ],
  "include": [
    "src/**/*.d.ts",
  ]
}
javascript angular lazy-loading angular8 angular9
2个回答
0
投票

在我的例子中,由于某些原因,导入语句中的文件名被capatilized了。

例如,假设我有以下.ts文件。companySearchModel.ts

export class CompanySearchModel {
    //some properties
}

在另一个文件中的导入语句,其中 companySearchModel 使用,看起来像这样。

import { CompanySearchModel } from './models/CompanySearchModel.ts'

当它应该看起来,像这样。

import { CompanySearchModel } from './models/companySearchModel.ts'

不知道为什么会这样,但希望这能帮到你。


0
投票

你可以在下面的tsconfig中添加这个路径来排除包括属性

"exclude": [
    "path/to/module"
  ]
© www.soinside.com 2019 - 2024. All rights reserved.