简体   繁体   English

找不到模块:错误:无法解析“ ./$$_gendir/app/app.app.module.ngfactory”

[英]Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'

I get this below error after upgrading my angular-cli 升级我的angular-cli后,出现以下错误

ERROR in Template parse errors:
Can't bind to 'index' since it isn't a known property of 'tag'. ("own)="handleKeydown($event, item)"
             (onTagEdited)="onTagEdited.emit(item)"
             [ERROR ->][index]="i"
             [attr.tabindex]="readonly ? -1 : 0"
             [class.readonly]="readonly""): TagInputComponent@16:13

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\xxxx\yyyy\eeeee\eeee\src'
 @ ./src/main.ts 5:0-74
 @ multi ./src/main.ts

This error happens when i run ng build --prod and works fine when i run ng build without any parameters, 当我运行ng build --prod时会发生此错误,当我运行没有任何参数的ng build时可以正常工作,

When you run the ng build in angular 2, latest angular-cli automatically runs with --aot parameter (ahead of time compilation), so it is trying to optimize your code. 当您在angular 2中运行ng构建时,最新的angular-cli自动使用--aot参数运行(提前编译),因此它正在尝试优化代码。 You are having a package that is not yet compatible for optimizing. 您所使用的软件包尚不兼容以进行优化。 So you need update to your packages. 因此,您需要更新软件包。 Most probably the packages that has **forRoot()** in your app.module.ts 最有可能在您的app.module.ts中具有**forRoot()**的软件包

I recommend to update all packages. 我建议更新所有软件包。

Easy way to update your package is to use ncu npm package as in below, which i got it from How do I correctly upgrade angular 2 (npm) to the latest version? 更新软件包的简单方法是使用如下所示的ncu npm软件包,我从如何正确将angular 2(npm)升级到最新版本中得到了它

Install 安装

npm install -g npm-check-updates

Usage 用法

ncu for display 显示用ncu

ncu -u for re-writing your package.json ncu -u用于重写package.json

and run npm install to update your packages 并运行npm install更新您的软件包

If above did not work, you might need to update your code for aot compliance. 如果上述方法不起作用,则可能需要更新代码以符合AOT要求。 Refer this url below to make changes in your code. 请参考下面的网址以更改代码。 https://medium.com/@isaacplmann/getting-your-angular-2-library-ready-for-aot-90d1347bcad https://medium.com/@isaacplmann/getting-your-angular-2-library-ready-for-aot-90d1347bcad

I had the same issue and how I ended up resolving it was: Delete the enhanced-resolve module from node_modules and then run 我遇到了同样的问题,最终得到了解决的方法是:从node_modules删除Enhanced-Resolve模块,然后运行

npm install enhanced-resolve@3.3.0

After that aot builds worked as expected... 在那之后,aot构建按预期工作了...

Use: 使用:

ng build --env=prod 

instead of: 代替:

ng build --prod

Faced second part of this issue. 面对这个问题的第二部分。

ERROR in ./src/main.ts
Can't resolve './$$_gendir/app/app.module.ngfactory'

Resolved it by updating angular/cli to 1.2.6 for angular 4 通过将angular 4的angular / cli更新为1.2.6来解决它

  1. Remove node_modules folder 删除node_modules文件夹
  2. Update "@angular/cli": "1.0.4" to "@angular/cli": "1.2.6" in package.json under devDependencies 在devDependencies下,将package.json中的“ @ angular / cli”:“ 1.0.4”更新为“ @ angular / cli”:“ 1.2.6”
  3. Run npm install 运行npm install

Then executing "ng build --prod" successfully generated the production build. 然后执行“ ng build --prod”成功生成了生产版本。

Same error after upgrading from Angular 6 to 7.1.4. 从Angular 6升级到7.1.4后出现相同的错误。 I followed the instructions found here . 我按照此处的说明进行操作。

The error returned was: 返回的错误是:

ERROR in ./src/main.server.ts
Module not found: Error: Can't resolve './app/app.server.module.ngfactory'

When trying to pre-render using the command. 尝试使用命令进行预渲染时。

ng run [my-project-name]:server

The reason was I enabled the Ivy Render which is not production ready . 原因是我启用了尚未准备就绪的Ivy Render。 By removing the lines: 通过删除行:

"angularCompilerOptions": {
  "enableIvy": true
} 

From the tsconfig.json file, all was well in the world again. 在tsconfig.json文件中,一切再次恢复了正常。

Apparently this unhelpful and confusing error message can be caused by using default exports in your typescript consumed by Angular AOT (prerendering). 显然,此无效和令人困惑的错误消息可能是由于在Angular AOT(演示)使用的打字稿中使用默认导出而引起的。 Using export default class will cause this error with any version of Angular and is currently unsupported. 使用export default class将在任何版本的Angular中导致此错误,并且当前不受支持。 You must change to export class . 您必须更改为export class

To view the current status of the issue and see if it ever gets fixed, see https://github.com/angular/angular/issues/11402 . 要查看问题的当前状态并查看问题是否得到解决,请参阅https://github.com/angular/angular/issues/11402 As of my writing this, the issue has been open for over two years, but they do claim it will get fixed one day. 在撰写本文时,这个问题已经开放了两年多,但他们确实声称它将在一天之内得到解决。

For me, I haven't declared my newly created component in module.ts. 对我来说,我没有在module.ts中声明我新创建的组件。 It worked when I declared it. 当我宣布它时,它起作用了。 Check if any of your components are not declared in module.ts. 检查是否在module.ts中未声明任何组件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到模块:错误:无法解析'./$$_gendir/app/app.module.ngfactory' - Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 找不到模块:错误:无法解析'./$$_gendir/app/app.module.ngfactory' - Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' Angular 4错误-./src/main.ts中找不到错误:错误:无法解析'./$$_gendir/app/app.app.module.ngfactory' - Angular 4 error - ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' 找不到模块:错误:无法解析$$ _ gendir \\ app \\ item-receive-return.module.ngfactory.ts' - Module not found: Error: Can't resolve $$_gendir\app\item-receive-return.module.ngfactory.ts' 找不到模块:错误:无法解析'./app.module.ngfactory'-离子3,角度5 - Module not found: Error: Can't resolve './app.module.ngfactory' - ionic 3, angular 5 ./ClientApp/boot.server.ts中的错误找不到模块:错误:无法解析'./../$$_gendir/ClientApp/app/app.app.server.module.ngfactory' - ERROR in ./ClientApp/boot.server.ts Module not found : error : Can't resolve './../$$_gendir/ClientApp/app/app.server.module.ngfactory' ./src/main.ts中的ngcli 6.1.3错误-无法解析'./app/app.module.ngfactory' - ngcli 6.1.3 ERROR in ./src/main.ts - Can't resolve './app/app.module.ngfactory' ./src/main/webapp/app/app.main.ts 中的 Jhipster webpack 生产错误,找不到模块:错误:无法解析“./app.module.ngfactory” - Jhipster webpack production ERROR in ./src/main/webapp/app/app.main.ts ,Module not found:Error: Can't resolve './app.module.ngfactory' AOT-找不到加载错误app.module.ngfactory - AOT - loading error app.module.ngfactory is not found 错误:无法解析“ C:\\ projects \\ Project-CMS \\ Project.Web \\ src”中的“ ./app/app.module.ngfactory” - Error: Can't resolve './app/app.module.ngfactory' in 'C:\projects\Project-CMS\Project.Web\src'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM