angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

You may need an appropriate loader for dynamic imports after upgrade to Angular 8

Open BrsJsk opened this issue 7 years ago • 35 comments

🐞 bug report

Description

I've updated my Angular 7 app to Angular 8. It used the old Angular way dynamic imports. i've ran ng update @angular/cli @angular/core, everything was updated properly and it was using the new standard for dynamic imports, but app cannot now be opened. It breaks during the compile process. This might be webpack issue?

🔬 Minimal Reproduction

Updated to Angular 8 and this error is throwing.

🔥 Exception or Error


ERROR in ./src/app/app-routing.module.ts 8:28
Module parse failed: Unexpected token (8:28)
You may need an appropriate loader to handle this file type.
|     {
|         path: 'auth',
>         loadChildren: () => import('./auth/auth.module').then(m => m.AuthModule)
|     },
|     {

🌍 Your Environment

Angular Version:


Angular CLI: 8.0.0
Node: 10.13.0
OS: darwin x64
Angular: 8.0.0

@angular-devkit/architect          0.800.0
@angular-devkit/build-angular      0.800.0
@angular-devkit/build-optimizer    0.800.0
@angular-devkit/build-webpack      0.800.0
@angular-devkit/core               8.0.0
@angular-devkit/schematics         8.0.0
@angular/cdk                       7.3.1
@angular/material                  7.3.1
@angular/material-moment-adapter   7.3.1
@ngtools/webpack                   8.0.0
@schematics/angular                8.0.0
@schematics/update                 0.800.0
rxjs                               6.5.2
typescript                         3.4.5
webpack                            4.30.0

BrsJsk avatar May 29 '19 16:05 BrsJsk

Rather than having to prefix html-loader! to every html import in your project, a better way to do this is to extend the webpack configuration and register the html extension to use the html loader.

I followed this tutorial to do that. Note you'll need to do this for both the build and the serve commands.

juliancarrivick avatar Jun 25 '19 01:06 juliancarrivick

I am facing this issue when upgrading to the latest version of angular and webpack. I also tried to install [email protected] but still getting this error.

hoangleitvn avatar Jun 28 '19 05:06 hoangleitvn

Hey guys, same error. None of above solution worked form.

I upgraded from angular 6 > angular 8

nimatrazmjo avatar Jul 01 '19 10:07 nimatrazmjo

I am running into the same issue after upgrading from angular 7.2 to 8.0.6

rm -rf node_modules
rm -f package-lock.json
npm install

did not work for me, neither did npm install [email protected] nor yarn

tsiegleauq avatar Jul 01 '19 15:07 tsiegleauq

rm -rf node_modules rm -f package-lock.json npm install

Try:

npm install acorn
rm -rf node_modules
rm -f package-lock.json
npm install

wootwoot1234 avatar Jul 03 '19 16:07 wootwoot1234

@wootwoot1234 That would uninstall acorn and never install it again since you are deleting node_modules after that .

I am stuck with this too.. I wonder how it worked well in Angular 6, but not on 7,8... :(

gs-akhan avatar Jul 03 '19 18:07 gs-akhan

@wootwoot1234 That would uninstall acorn and never install it again since you are deleting node_modules after that .

I am stuck with this too.. I wonder how it worked well in Angular 6, but not on 7,8... :(

By default npm install acorn will add it to your package.json. Then npm install will reinstall it. It worked for me.

wootwoot1234 avatar Jul 03 '19 18:07 wootwoot1234

It did work. :( but gives a guilty feeling. I hope this issue is natively fixed.

gs-akhan avatar Jul 03 '19 20:07 gs-akhan

my issue was that I probably updated too far. I created a new angular project using Angluar-CLI version 8.0.6, copied the package.json, migrated all other angular files by hand and got it working.

tsiegleauq avatar Jul 04 '19 08:07 tsiegleauq

Just ran into this problem after upgrading from Angular 7 to 8.1... This fixed the problem for me:

rm -rf node_modules
rm package-lock.json
npm install --save-exact [email protected]
npm install

TekTimmy avatar Jul 05 '19 11:07 TekTimmy

acorn & webpack got updated. If you use webpack >= 4.35.3, this issue is fixed.

sod avatar Jul 09 '19 14:07 sod

Per @sod's comment, currently angular-devkit/build-angular requires webpack 4.35.2.

phrough avatar Jul 15 '19 21:07 phrough

Just ran into this problem after upgrading from Angular 7 to 8.1... This fixed the problem for me:

rm -rf node_modules
rm package-lock.json
npm install --save-exact [email protected]
npm install

It worked for me, here is my version details:

Angular CLI: 8.1.2
Node: 10.16.0
OS: win32 x64
Angular: 8.1.2
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.801.2
@angular-devkit/build-angular     0.801.2
@angular-devkit/build-optimizer   0.801.2
@angular-devkit/build-webpack     0.801.2
@angular-devkit/core              8.1.2
@angular-devkit/schematics        8.1.2
@angular/cdk                      8.1.1
@angular/flex-layout              8.0.0-beta.26
@angular/material                 8.1.1
@ngtools/webpack                  8.1.2
@schematics/angular               8.1.2
@schematics/update                0.801.2
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.35.2

tasnim-reza avatar Jul 18 '19 09:07 tasnim-reza

Just to let people know, I got it working with NPM doing the following :

npm i angular-devkit/[email protected]
rm package-lock.json
rm -rf node_modules
npm i

Doing that makes everything works afterward. If you look at the installed packages, you can see that acorn is now at the proper version : image

Hope this help someone :)

maroy1986 avatar Aug 06 '19 14:08 maroy1986

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.