Skip to content

require html stopped working in upgrade to angular 8 #14855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
icorne opened this issue Jun 21, 2019 · 11 comments
Closed

require html stopped working in upgrade to angular 8 #14855

icorne opened this issue Jun 21, 2019 · 11 comments

Comments

@icorne
Copy link

icorne commented Jun 21, 2019

Command (mark with an x)

- [ ] new
- [ x] build
- [x ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

Yes, the previous version in which this bug was not present was: 7.x

Description

When trying to require an html file in using @angular/cli 8 it fails, it works in angular 7

🔬 Minimal Reproduction

I made repro branches. Be sure to npm install when switching between branches.
ng 7 generated project with node types added
https://github.com/icorne/ng-import-html/tree/ng7-import-html

same project, upgraded with ng update @angular/cli @angular/core
https://github.com/icorne/ng-import-html/tree/ng8-import-html

🔥 Exception or Error


ERROR in ./src/app/template.html 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
> I am a required template file

🌍 Your Environment


   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 8.0.3
Node: 12.3.1
OS: linux x64
Angular: 8.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.3
@angular-devkit/build-angular     0.800.3
@angular-devkit/build-optimizer   0.800.3
@angular-devkit/build-webpack     0.800.3
@angular-devkit/core              8.0.3
@angular-devkit/schematics        8.0.3
@angular/cli                      8.0.3
@ngtools/webpack                  8.0.3
@schematics/angular               8.0.3
@schematics/update                0.800.3
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.30.0

Anything else relevant?
This is import for me because i'm using a hybrid project angular/angularJs, and for this to work, you cannot use templateUrl

@alan-agius4 alan-agius4 added this to the 8.0.x milestone Jun 21, 2019
@ngbot ngbot bot removed this from the 8.0.x milestone Jun 21, 2019
@ngbot ngbot bot added this to the Backlog milestone Jun 21, 2019
@alan-agius4 alan-agius4 self-assigned this Jun 21, 2019
@icorne
Copy link
Author

icorne commented Jun 26, 2019

thanks @alan-agius4 !

@icorne
Copy link
Author

icorne commented Jun 26, 2019

I would say "by some angularjs applications" is an understatement, unless there's another clean way to have html files imported?

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Jun 28, 2019

Hi, can you kindly explain why you cannot use templateUrl with AngularJs? As checked with @clydin and he mentioned that this should work.

Thanks.

@icorne
Copy link
Author

icorne commented Jun 28, 2019

I get the following error at runtime:
app.module.ts:38 Error: loading directive templates asynchronously is not supported at Function.push../node_modules/@angular/upgrade/fesm5/static.js.UpgradeHelper.getTemplate (static.js:1080) [angular] at UpgradeHelper.push../node_modules/@angular/upgrade/fesm5/static.js.UpgradeHelper.compileTemplate (static.js:1108) [angular] at LandingDirective.push../node_modules/@angular/upgrade/fesm5/static.js.UpgradeComponent.ngOnInit (static.js:1375) [angular] at checkAndUpdateDirectiveInline (core.js:22099) [angular] at checkAndUpdateNodeInline (core.js:23363) [angular] at checkAndUpdateNode (core.js:23325) [angular] at debugCheckAndUpdateNode (core.js:23959) [angular] at debugCheckDirectivesFn (core.js:23919) [angular] at Object.eval [as updateDirectives] (LandingComponent.html:1) [angular] at Object.debugUpdateDirectives [as updateDirectives] (core.js:23911) [angular] at checkAndUpdateView (core.js:23307) [angular] at callViewAction (core.js:23548) [angular] at execComponentViewsAction (core.js:23490) [angular] at checkAndUpdateView (core.js:23313) [angular]

@icorne
Copy link
Author

icorne commented Jun 28, 2019

Furthermore, the require way was working before, but not anymore...

@Camo30
Copy link

Camo30 commented Jul 4, 2019

Hi @alan-agius4, this won't work with templateUrl as there was this bug #11523. I've changed all templateUrl to template: require() and it has worked - until now.

As a temporary workaround I've added this package to the project and replaced all template: require(...) with template: require('html-loader!...'), for now it works again.

@alan-agius4 alan-agius4 added the needs: discussion On the agenda for team meeting to determine next steps label Jul 4, 2019
@FDIM
Copy link
Contributor

FDIM commented Jul 4, 2019

For me using require('!raw-loader!./path-to-template.html') worked. Not sure how long it will work, but hopefully we will be done with upgrade of components by then

@icorne
Copy link
Author

icorne commented Jul 8, 2019

For me using require('!raw-loader!./path-to-template.html') worked. Not sure how long it will work, but hopefully we will be done with upgrade of components by then

That works (for now) for me as well.

@JochenDiekenbrock
Copy link

To circumvent this bug, if you have a lot of imports/requires, instead of changing them all, you could also use ngx-build-plus and add "extraWebpackConfig": "webpack.partial.js" in angular.json to extend the webpack configuration.

webpack.partial.js:

const webpack = require('webpack');

module.exports = {
	module: {
		rules: [
			{ test: /\.html$/, loader: 'raw-loader' }
		],
	}
};

@alan-agius4 alan-agius4 removed the freq1: low Only reported by a handful of users who observe it rarely label Jul 11, 2019
@ngbot ngbot bot modified the milestones: Backlog, needsTriage Jul 11, 2019
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Jul 11, 2019
@alan-agius4
Copy link
Collaborator

Hi all, we had a chat around this, and we think that if you want to use webpack specific stuff you can use ngx-build-plus or otherwise you can update the require statements to include the raw-loader import syntax ie: require('!raw-loader!./path-to-template.html') as suggested above.

Note: Webpack specific features might not work in the future.

We apologies for any inconvenience this might cause.

@alan-agius4 alan-agius4 removed the needs: discussion On the agenda for team meeting to determine next steps label Jul 11, 2019
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.