ng build --prod throwing errr

时间:2017-12-18 06:03:52

标签: angular build angular2-routing angular-cli

I am using ng build --prod command but it is showing error like

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './app/app.module.ngfactory' in 'C:\Users\allud\MyCafe\src'
resolve './app/app.module.ngfactory' in 'C:\Users\allud\MyCafe\src'
  using description file: C:\Users\allud\MyCafe\package.json (relative path: ./src)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: C:\Users\allud\MyCafe\package.json (relative path: ./src)
    using description file: C:\Users\allud\MyCafe\package.json (relative path: ./src/app/app.module.ngfactory)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\allud\MyCafe\src\app\app.module.ngfactory doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\allud\MyCafe\src\app\app.module.ngfactory.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        C:\Users\allud\MyCafe\src\app\app.module.ngfactory.js doesn't exist
      as directory
        C:\Users\allud\MyCafe\src\app\app.module.ngfactory doesn't exist
[C:\Users\allud\MyCafe\src\app\app.module.ngfactory]
[C:\Users\allud\MyCafe\src\app\app.module.ngfactory.ts]
[C:\Users\allud\MyCafe\src\app\app.module.ngfactory.js]
[C:\Users\allud\MyCafe\src\app\app.module.ngfactory]
 @ ./src/main.ts 3:0-66
 @ multi ./src/main.ts

2 个答案:

答案 0 :(得分:0)

Seems line node caching module issue. Please try below given commands:

cd {your-project}
npm -f cache clean 
rm -f package-lock.json
rm -rf node_modules
npm install

If it does not work clean you .npm and .node-gyp in the home directory.

答案 1 :(得分:0)

There are few things you can verify,

  1. Check whether you are loading the components from the correct directory, I mean the path of the components in Import statements

    import PackageName from './FromFolder';
    
  2. Remove node_modules and reinstall all the packages

  3. Update your Angular CLI version with updated packages

Now try ng build --prod