<!--
Angular CLI: 1.7.3
Node: 9.8.0
OS: darwin x64
Angular: 5.2.9
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router
@angular/cdk: 5.2.4
@angular/cli: 1.7.3
@angular/flex-layout: 5.0.0-beta.13
@angular/material: 5.2.4
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack-node-externals: 1.6.0
webpack: 3.10.0
Cannot find module '@angular-devkit/build-optimizer' from '/my/project/directory'
Error: Cannot find module '@angular-devkit/build-optimizer' from '/my/project/directory'
at Function.module.exports [as sync] (/my/project/directory/node_modules/resolve/lib/sync.js:40:15)
at Object.getCommonConfig (/my/project/directory/node_modules/@angular/cli/models/webpack-configs/common.js:138:56)
at NgCliWebpackConfig.buildConfig (/my/project/directory/node_modules/@angular/cli/models/webpack-config.js:33:31)
at Class.run (/my/project/directory/node_modules/@angular/cli/tasks/build.js:31:92)
at Class.run (/my/project/directory/node_modules/@angular/cli/commands/build.js:250:40)
at resolve (/my/project/directory/node_modules/@angular/cli/ember-cli/lib/models/command.js:261:20)
at new Promise (<anonymous>)
at Class.validateAndRun (/my/project/directory/node_modules/@angular/cli/ember-cli/lib/models/command.js:240:12)
at Promise.resolve.then.then (/my/project/directory/node_modules/@angular/cli/ember-cli/lib/cli/cli.js:140:24)
at <anonymous>
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build:prod: `ng build --prod`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build:prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Mark/.npm/_logs/2018-03-20T12_06_15_012Z-debug.log
To build prod without error
My project's package.json
"dependencies": {
"@angular/animations": "^5.2.9",
"@angular/cdk": "^5.2.4",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/flex-layout": "^5.0.0-beta.13",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/material": "^5.2.4",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/platform-server": "^5.2.9",
"@angular/router": "^5.2.0",
"@ngrx/effects": "^4.1.0",
"@ngrx/store": "^4.1.0",
"@nguniversal/express-engine": "^5.0.0-beta.6",
"@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.6",
"@ngx-translate/core": "^9.1.1",
"@ngx-translate/http-loader": "^2.0.1",
"bodybuilder": "2.2.1",
"core-js": "^2.4.1",
"elasticsearch": "^13.3.1",
"hammerjs": "^2.0.8",
"intl": "^1.2.5",
"jsdom": "^11.6.2",
"jsdom-global": "^3.0.2",
"libphonenumber-js": "^1.0.24",
"rxjs": "^5.5.6",
"ts-loader": "^3.5.0",
"web-animations-js": "^2.3.1",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "~1.7.3",
"@angular/compiler-cli": "^5.2.0",
"@ngrx/store-devtools": "^4.0.0",
"@types/googlemaps": "^3.30.0",
"@types/jasmine": "~2.8.3",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"node-sass": "^4.7.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3",
"webpack": "^3.10.0",
"webpack-node-externals": "^1.6.0"
}
NPM was working fine for me, but then it suggested I update npm from 5.6.0 to 5.7.1. I ran "npm i npm", and after that was done, I started getting the above error. (NPM claimed it probably wasn't being caused by npm.)
I then ran "npm update" (as administrator), and now I'm no longer getting this error.
Not sure if this means anything to anyone, but I thought I'd at least log my experience in case it helps someone figure out what's causing this error.
So I tried to fix it by running
yarn add @angular-devkit/build-optimizer --dev
And it worked. Quite weird.
You could do the same with npm by doing
npm i @angular-devkit/build-optimizer --save-dev
Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.
If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
So I tried to fix it by running
And it worked. Quite weird.
You could do the same with npm by doing