ng build –prod打包项目出错
错误描述:
ng build 打包正常,顺利生成dist;但在使用ng build –prod生成时提示错误:
ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\phpStudy\WWW\html\zxttByng\src' @ ./src/main.ts 3:0-74 @ multi ./src/main.ts
解决方法:
修改package.json中@angular/cli的版本与全局安装的@angular/cli版本保持一致。
"devDependencies": { "@angular/cli": "1.2.7", "@angular/compiler-cli": "^4.0.0", "@angular/language-service": "^4.0.0", "@types/jasmine": "~2.5.53", "@types/jasminewd2": "~2.0.2", "@types/node": "~6.0.60", "codelyzer": "~3.0.1", "jasmine-core": "~2.6.2", "jasmine-spec-reporter": "~4.1.0", "karma": "~1.7.0", "karma-chrome-launcher": "~2.1.1", "karma-cli": "~1.0.1", "karma-coverage-istanbul-reporter": "^1.2.1", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.1.2", "ts-node": "~3.0.4", "tslint": "~5.3.2", "typescript": "~2.3.3" }
D:\phpStudy\WWW\html\zxttByng>ng version _ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | | / ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | | /_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___| |___/ @angular/cli: 1.2.7 ..... ....
删除node_modules文件夹以及package-lock.json,重新执行npm install 命令,安装依赖即可。注意删除package-lock.json,否则安装依赖无效,使用依旧是修改前的版本。