angular cli beta.16 doesn't work after upgrading to beta 22 and returning to beta.16
I have upgreded angular cli to beta.22 to test aot , and since it doesn't work yet I desided to return back to beta.16 and complete my project util aot becomes available, and the probelm is that beta.16 also doesn't work any more here is errors I get : ng new : fs.js:549 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^
TypeError: path must be a string at TypeError (native) at Object.fs.openSync (fs.js:549:18) at Object.fs.readFileSync (fs.js:397:15) at Function.Version.fromProject (C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\upgrade\version.js:87:31) at Function.Version.isPreWebpack (C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\upgrade\version.js:111:31) at Function.Version.assertPostWebpackVersion (C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\upgrade\version.js:97:18) at C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\bin\ng:25:15 at C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\node_modules\resolve\lib\async.js:45:21 at ondir (C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\node_modules\resolve\lib\async.js:188:31) at C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\node_modules\resolve\lib\async.js:154:39
ng --version : fs.js:549 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^
TypeError: path must be a string at TypeError (native) at Object.fs.openSync (fs.js:549:18) at Object.fs.readFileSync (fs.js:397:15) at Function.Version.fromProject (C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\upgrade\version.js:87:31) at Function.Version.isPreWebpack (C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\upgrade\version.js:111:31) at Function.Version.assertPostWebpackVersion (C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\upgrade\version.js:97:18) at C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\bin\ng:25:15 at C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\node_modules\resolve\lib\async.js:45:21 at ondir (C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\node_modules\resolve\lib\async.js:188:31) at C:\Users\khaled_bo\AppData\Roaming\npm\node_modules\angular-cli\node_modules\resolve\lib\async.js:154:39
I don't believe downgrading your CLI is supported or possible, especially that many versions at once.
What you should do is move to beta-22 and fix your app's issues with AoT because it works just fine (Except custom decorators for the moment). Even if you don't want to use AoT the new beta will continue to work with JIT compilation. AoT usually doesn't work because your code isn't able to be analyzed properly. If this is the case the JiT compiler may never see an issue if the code isn't run, or it may guess correctly and you never notice, but that doesn't mean your code is "correct" to the AoT compiler.
It took me about two hours to move from beta-16 to beta-20.4. I had modules that weren't resolving promises in just the right way, so after going over each service with a fine tooth comb I was able to get AoT working. It really just takes a little diligence. The compile time is way down in beta-22 even compared to beta-20.4, and AoT dev mode is many times lighter and faster than JiT with --prod.
I belive aot with lazy loading doesn't work yet ( I generated all the ngfactory files but when I run the application the lzay loaded moduls could not be found ). I created an application using angular-cli beta.16 , when I saw the new version of angular-cli ( beta.22 ) I decided to try it to see if it works fine with aot and lazy loding , but when it didn't works for me I deleted it , and installed the beta.16 again and I couldn't get it to work as before ( before I installed and unistalled the beta.22) note: I alsoe tried to install the beta.16 in an other pc but it didn't work
@khaledbouguerra I can confirm that lazy loading does work with AoT, you just have to have the application setup correctly, Lazy Loading and AoT were fixed in beta.21 and i have been using it since it was released.
Did you ng init when you used Beta-22? If you did, you'll have to ng init again and undo those changes, plus make sure to npm install again to get the proper dependencies back. Even then there's likely some differences that you'll have to track down (Reinstalling any dependencies that got semvered to an incompatible version for example.) Also, be sure to match your local and global installations or you're going to have a bad time.
Like I said though, upgrading to the newest and continuing to use JIT should work just fine, but downgrading isn't likely to work for you without a lot of hassle.
You also shouldn't need explicit NgFactory files, as the AoT command produces them. All you need are the proper routes (I'm lazy loading my entire app with AoT as of today.)
I generated the NgFactory fils using ngc "node_modules/.bin/ngc" -p tsconfig-aot.json( windows command) ,at first it didn't work so I fixed all the compiling errors to get it to produce the NgFactory files , but as I said when I run the app I get the " couldn't find LoginRegiter NgModule" ( which is the lazy loaded module) PS: I tried aot without lazy loding and it worked like a charme, Also I didn't use the tow angular-cli versions in the same project , infact I installed [email protected] and tried to creat a new project with it but it didn't work so I unistalled it and installed the beta.16 but it didn't work ,
@khaledbouguerra with the Angular-CLI you do not need to use ngc, you simply add the -aot flag to ng serve or ng build and it handles all of the AoT for you.
I had mixed results with beta.22-1 so i reverted to beta.21 and i am waiting for beta.23 to come out.
You should read over this (Lazy Loading Tutorial) and this (Avoid AoT & Lazy Loading Pitfalls they are extremely valuable when dealing with lazy loading and AoT they also cover most cases that cause lazy loading or AoT to not function properly.
I upgraded to angular-cli beta.21 it works fine expect the aot ! get this error when i run ng serve --prod --aot : webpack_1.NgcWebpackPlugin is not a function TypeError: webpack_1.NgcWebpackPlugin is not a function at Object.exports.getWebpackAotConfigPartial (E:\angular 2\cli simple project\expert-perpa-logic\node_modules\angular-cli\models\webpack-build-typescript.js:50:13) at new NgCliWebpackConfig (E:\angular 2\cli simple project\expert-perpa-logic\node_modules\angular-cli\models\webpack-config.js:18:42) at Class.exports.default.Task.extend.run (E:\angular 2\cli simple project\expert-perpa-logic\node_modules\angular-cli\tasks\serve-webpack.js:19:22) at E:\angular 2\cli simple project\expert-perpa-logic\node_modules\angular-cli\commands\serve.js:85:26 at tryCatch (E:\angular 2\cli simple project\expert-perpa-logic\node_modules\es6-promise\dist\lib\es6-promise-internal.js:195:12) at invokeCallback (E:\angular 2\cli simple project\expert-perpa-logic\node_modules\es6-promise\dist\lib\es6-promise-internal.js:210:13) at publish (E:\angular 2\cli simple project\expert-perpa-logic\node_modules\es6-promise\dist\lib\es6-promise-internal.js:178:7) at flush (E:\angular 2\cli simple project\expert-perpa-logic\node_modules\es6-promise\dist\lib\es6-promise\asap.js:94:5) at nextTickCallbackWith0Args (node.js:419:9) at process._tickCallback (node.js:348:13)
E:\angular 2\cli simple project\expert-perpa-logic>
@khaledbouguerra you need to remove node_modules/angular-cli, node_modules/@angular-cli and node_modules/@ngtools then you need to have angular cli installed system wide npm install -g [email protected] and locally in your repo npm install --save-dev [email protected].
The global tool uses the local scripts to do building/serving, the error you're seeing is a is a leftover from an mismatched @ngtools/webpack package which is installed by angular-cli so either the local angular-cli or the global one is the incorrect version most likely (or the @ngtools/webpack wasn't reinstalled)
thank you for your help guys ! it turns out that [email protected] does support aot and lazyoading only when using angular 2.2.1 , not the previous versions
@khaledbouguerra I didn't realize that before 2.2.1 it was broken, but this isn't surprising as that's when ngc got some real attention (which angular-cli uses via a custom webpack plugin) i am on 2.2.4 and AoT + LazyLoading is also working there.
Hey thanks for all the help getting this issue sorted, you guys are great!
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.