找不到模块:错误:无法解析'。/ $ _ gendir / app / app.module.ngfactory'在

时间:2017-07-27 14:53:26

标签: node.js angular

我知道有关path: path.resolve(__dirname, target)的问题在这里被多次询问过。但是,我认为这是一个安静有趣的情况 我想在下面描述一下:

我在运行Ubuntu 16.10和Ubuntu 17.04的2台机器上安装了节点。

1。在ubuntu 16.04

通过以下命令行安装节点:

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

2。在ubuntu 17.04

Ubuntu 17.04已经有了新版本的节点。安装通过

完成
sudo apt-get install python-software-properties
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install nodejs

3。两台机器有什么共同之处?

3.1。 node和npm的版本是:

sudo apt-get install nodejs

3.2。 angular4应用程序是通过@ angular / cli

创建的
node -v
# v7.10.0

npm -v
# 4.2.0

3.3。使用docker

的angular4应用程序的githbub上的repo

两台机器都使用相同的仓库angular4-on-nginx-with-docker

4。有什么区别???

4.1。在Ubuntu 16.10上

sudo npm install -g @angular/cli
ng new my-app

PS: $ ng build --prod Hash: 64b40519b4565aa62e0b Time: 10106ms chunk {0} polyfills.71b130084c52939ca448.bundle.js (polyfills) 177 kB {4} [initial] [rendered] chunk {1} main.e81f19d3f6b27a436c79.bundle.js (main) 1.09 kB {3} [initial] [rendered] chunk {2} styles.d41d8cd98f00b204e980.bundle.css (styles) 69 bytes {4} [initial] [rendered] chunk {3} vendor.f7457d5ac1e9743fd76f.bundle.js (vendor) 849 kB [initial] [rendered] chunk {4} inline.18e445e37a0efd4dcfa2.bundle.js (inline) 0 bytes [entry] [rendered] ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/home/amine/DockerProjects/tt/nginx/frontend/src' @ ./src/main.ts 3:0-74 @ multi ./src/main.ts 是:

./src/main.ts

4.2。在Ubuntu 17.04

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);

5。问题

两台机器的代码都是一样的!只需$ ng build --prod Hash: ab00cb280399614d6ea9 Time: 16640ms chunk {0} polyfills.71b130084c52939ca448.bundle.js (polyfills) 177 kB {4} [initial] [rendered] chunk {1} main.97abdc47ac3699c01fa5.bundle.js (main) 5.27 kB {3} [initial] [rendered] chunk {2} styles.d41d8cd98f00b204e980.bundle.css (styles) 69 bytes {4} [initial] [rendered] chunk {3} vendor.0a8aa978ae08e1954b1c.bundle.js (vendor) 1.89 MB [initial] [rendered] chunk {4} inline.3da3f5efaa0601772495.bundle.js (inline) 0 bytes [entry] [rendered] 命令行来获取代码。那么,使用 AOT 进行编译并在另一台机器上运行失败有什么不同?

谢谢,,,

2 个答案:

答案 0 :(得分:13)

使用"enhanced-resolve":"3.3.0"是旧版"@angular/cli"的解决方案,例如"1.2.3"

另一种解决方案,使用"@angular/cli": "1.2.6"

答案 1 :(得分:1)

使用ng build --env=prod代替ng build --prod。当我创建一个全新的项目并运行ng build --prod时,出现Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'错误。但当我跑ng build --env=prod时,dist生成正常。