Skip to content
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

(0.6.1) path problem #50

Open
nick1247 opened this issue Feb 6, 2017 · 31 comments · Fixed by #52 · May be fixed by #67
Open

(0.6.1) path problem #50

nick1247 opened this issue Feb 6, 2017 · 31 comments · Fixed by #52 · May be fixed by #67

Comments

@nick1247
Copy link

nick1247 commented Feb 6, 2017

0.6.1 version doesn't recognize some of my relative paths.

This component

@Component({
	selector: 'home',
	templateUrl: 'home.component.html'
})
export class HomeComponent ...

builds to

HomeComponent = __decorate([
    core_1.Component({
        selector: 'home',
        templateUrl: 'home.component.html'
    }),
    __metadata("design:paramtypes", [router_1.ActivatedRoute])
], HomeComponent);

Looks like loader doesn't recognize templateUrl path.

When I roll back to 0.6.0 it works fine.

@dellax
Copy link

dellax commented Feb 6, 2017

same problem

@nick1247
Copy link
Author

nick1247 commented Feb 6, 2017

This should fix it.
@dellax as temporary workaround you can add the comma symbol after templateUrl

@tonimitrevski
Copy link

same problem

@nick1247
Copy link
Author

nick1247 commented Feb 6, 2017

@tonimitrevski do u have the same problem with teplateUrl ended with comma symbol?

@Component({
	selector: 'home',
	templateUrl: 'home.component.html', // <<--
})
export class HomeComponent ...

@tonimitrevski
Copy link

yup , but i try withcomma and it's fixed, but i have 100 component's that is the problem for now :)

@jeka5555
Copy link

jeka5555 commented Feb 6, 2017

because of you, I spent the whole day, until I realized that this is a bug after upgrading to 0.6.1

@TheLarkInn
Copy link
Owner

Hey sorry about this folks. I'll take a look at this and fix right away.

@TheLarkInn
Copy link
Owner

I don't have time to publish this just yet as I have to run, but I will be happy to do so tonight or tomorrow.

@TheLarkInn TheLarkInn reopened this Feb 7, 2017
@TheLarkInn
Copy link
Owner

Going to leave open until I publish fix. Thanks for your patience everyone.

@mohannad-abwah
Copy link

mohannad-abwah commented Feb 7, 2017

@TheLarkInn Have you had a chance to publish the fix yet?

@TheLarkInn
Copy link
Owner

Closing as this is now published, thank you so much for being patient. Also looking for maintainers willing to help.

@FabianGosebrink
Copy link

Works again, thank you. Would be glad to help! Sent you an email but no response. How can I get in contact with you best?

@scoleman81
Copy link

I think there still may be a issue here. I am really new to angular 2 and web pack. Working on my first project. I built from scratch using Full framework and the spa template as an example. Using version 0.6.2 in both and the core(standard 1.0) works fine like everyone else says. the Core(full .net) gives the same error as before. I was able to get the core(full) to work by going to 0.6.0 and adding the require statements as talked about above. I don't really understand how these two could be different since all of this should not be dependent on the framework but I can't figure it out.

@GiuseppePiscopo
Copy link

GiuseppePiscopo commented Mar 21, 2017

Hi everyone,
it seems to me I'm getting into the same issue. Put my hands back on a project that I left for a couple of weeks, and now got this new errors.

Building and bundling goes fine, but then at runtime in dev console I see a couple of wrong HTML requests:

GET http://localhost:51254/templates/default/color-picker.component.html 404 (Not Found)
GET http://localhost:51254/component.html 404 (Not Found)

with their accompanying Failed to load ... error messages. It seems like all of a sudden relative templateUrl are not respected anymore. Originally those are:

// some component file
templateUrl: './templates/default/color-picker.component.html',

// another component file
templateUrl: './component.html',

and, by chance (for our code convetion), there's already a trailing comma. I also tried swapping single quotes for double quotes.

I tried with angular2-template-loader 0.6.0 and 0.6.2, with no luck. Other dependencies:

Side note, in case might be related:
before this runtime problem, I incurred into a new build time error, apparently due to an issue with awesome-typescript-loader, which required upgrading that dependency.

EDIT bundled JS code still shows templateUrl: "./templates/default/color-picker.component.html", while I guess it should have transformed that into some template: require(...), if I recall correctly

@nikolasleblanc
Copy link

@GiuseppePiscopo, do any of your other templateUrls have this issue, or is it specific to these two templateUrls, or do you only have two components? It would be good if you could post the full @component metadata for each of these two cases.

Also, just because why not, have you tried without the ./ at the beginning of the templateUrl?

@GiuseppePiscopo
Copy link

GiuseppePiscopo commented Mar 22, 2017

No. All templateUrls instances show up untouched in generated main-bundle.js. I have a couple of components with template, they of course are left with their string content. Then some components from node_modules dependencies show template with string content, but again those do not matter here.

Same happens for styleUrls. Here's one of the many and similar component metadata, which worked until now:

@Component({
  selector: '[sideBar]',
  templateUrl: './component.html',
  styleUrls: ['./component.css'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SideBarComponent {
  // ...
}

found in some my\project\path\src\private\view\side-bar\ subdirectory, containing component.[css|html|ts]

Tried also with templateUrl: 'component.html', or templateUrl: 'templates/default/color-picker.component.html', for another component: no change.

EDIT Webpack configuration has not changed since switching from 2.1.0-beta.25 to 2.2.1. For typescript in JIT build is:

    test: /\.ts$/,
    use: [
      'awesome-typescript-loader',
      'angular2-template-loader',
      'angular-router-loader',
    ],
    include: [
      paths.clientSrc,
    ],
    exclude: [
      paths.nodeModules, // skip all node modules
      paths.buildOutput, // skip output
      paths.codegen, // skip (AOT) generated code
      /\.(spec|e2e|async)\.ts$/, // skip all test and async TS files
    ],

@GiuseppePiscopo
Copy link

GiuseppePiscopo commented Mar 22, 2017

Oh well ... more findings: production AOT build goes fine and show no errors in console. Its (multiple) chunks generated out of custom code show all my templateUrl turned into template + content still as templateUrl + relative path.

AOT build has typescript loaders changed to:

  typescript: {
    test: /\.ts$/,
    use: [
      'awesome-typescript-loader?silent=true',
      'angular2-template-loader',
      'angular-router-loader?aot=true&debug=false&genDir=./codegen',
    ],
    include: [
      paths.clientSrc,
      paths.codegen, // include (AOT) generated code
    ],
    exclude: [
      paths.nodeModules, // skip all node modules
      paths.buildOutput, // skip output
      /\.(spec|e2e|async)\.ts$/, // skip all test and async TS files
    ],
  },

Development JIT build instead has only a main bundle for our custom code (beside vendor bundle, that is). But this main bundle only has components common to whole app, and their templateUrl is untouched. Furthermore, there are no component from other "lazy loaded" modules. It's like if angular-router-loader had no effect at all in JIT build.

By peeking at other sample projects, JIT bundle should instead show something like template: __webpack_require__(/*! ./hero-detail.component.html */ 633),, right?

@GiuseppePiscopo
Copy link

I temporarily added logs to node_modules\angular2-template-loader\index.js, and replacement between original source and newSource does work:

  • Original: templateUrl: './not-found.component.html',
  • Replaced: template: require('./not-found.component.html'),

But indeed when I look at whole bundled JS, I find:

NotFoundComponent = tslib_1.__decorate([
    core_1.Component({
        selector: 'not-found',
        templateUrl: './not-found.component.html',
        styles: ["\n    .container {\n      margin-top: 40px;\n    }\n  "],
    }),
    tslib_1.__metadata("design:paramtypes", [router_1.Router])
], NotFoundComponent);

as if loader output is somehow ignored.

@nikolasleblanc
Copy link

Are you using the latest versions of angular2-template-loader and awesome-typescript-loader? If not, you may need the config settings that were removed in this commit: beb5b95#diff-04c6e90faac2675aa89e2176d2eec7d8L65

@GiuseppePiscopo
Copy link

GiuseppePiscopo commented Mar 22, 2017

Thanks for suggestion @nikolasleblanc . Project is using current latest versions:

+-- [email protected]
+-- [email protected]
+-- [email protected]

I missed that change in awesome-typescript-loader settings, hence this project still kept "useWebpackText": true in its tsconfig.json files. I tried just now deleting that bit, leaving an empty "awesomeTypescriptLoaderOptions": {}, but nothing changed.

One more finding, which I think is moving the culprit somewhere else, is the following: I temporarily turned on debugging in angular-router-loader, and at least from its output one can say that replacement does happen:

[angular-router-loader]: Original: loadChildren: '../private/module#PrivateModule'
[angular-router-loader]: Replacement: loadChildren: () => new Promise(function (resolve) { (require as any).ensure([], function (require: any) { resolve(require('..\private\module')['PrivateModule']); })

while in main-bundle.js I still find loadChildren: '../private/module#PrivateModule',. So, again, it looks like those two loaders output is not fed into awesome-typescript-loader, or anyway does not make it to the final bundling phase.

@GiuseppePiscopo
Copy link

GiuseppePiscopo commented Mar 22, 2017

One step more: temporarily added console logs to node_modules\awesome-typescript-loader\dist\index.js (original TS here), dumping text and resultText within transform function. Result seems quite strange to me:

Input text (excerpt):

// ...
@Component({                                                 
  selector: 'not-found',                                     
  template: require('./not-found.component.html'),           
  styles: [`                                                 
    .container {                                             
      margin-top: 40px;                                      
    }                                                        
  `],                                                        
})                                                           
export class NotFoundComponent implements OnInit {
// ...

Output text (excerpt):

// ...
NotFoundComponent = tslib_1.__decorate([
    core_1.Component({
        selector: 'not-found',
        templateUrl: './not-found.component.html',
        styles: ["\n    .container {\n      margin-top: 40px;\n    }\n  "],
    }),
    tslib_1.__metadata("design:paramtypes", [router_1.Router])
], NotFoundComponent);
// ...

?? why decorate shows back initial, original templateUrl instead of template + require, or something else? Might that be related to using tslib helpers instead of webpack TS helpers? EDIT Answer: nope, even skipping tslib helpers, same thing, with __decorate in place of tslib_1.__decorate.

@GiuseppePiscopo
Copy link

@nikolasleblanc still interested in some kind of repro?

@nikolasleblanc
Copy link

Sure if you've got one handy. Sorry, got swamped.

@GiuseppePiscopo
Copy link

No need for excuse. Sure, I'll send you something by email.

@habibialkaff
Copy link

habibialkaff commented Jun 8, 2017

Hi @GiuseppePiscopo, did you manage to sort out the issue? I'm having the same problem, 2 of my components template are reset back to "templateUrl".
The regex matching is not the issue. Like you said, it seems that the result of this loader is not fed into the at-loader

My current workaround is to swap angular2-template-loader and awesome-typescript-loader

@GiuseppePiscopo
Copy link

Hi there. At that time, I found some alternative workarounds:

  1. Move project to another path. Yes, definitely absurd, but I had the issue come and go when changing path. In detail, the original path was longer, but nothing exaggerated. And had no blanks in it.

  2. Similar to previous, create a symlink at a different path. This worked, but for some reason it breaks AOT build

  3. As you found, switch to another TS loader

Now, more recently, I'm running the build not from standalone command prompt, but from VS Code integrated terminal and for some reason I got no error, with project still being at original path. I also upgraded angular and webpack in meantime, but I'm not sure that matters. HTH

@GiuseppePiscopo
Copy link

Sorry, item 3: what I described is not the same switch as you described

@reiday
Copy link

reiday commented Sep 7, 2017

I encountered what might be the same problem; I found out the problem was that I had a bunch of compiled .js files lying around from running tsc manually. Deleting them resolved the issue, so what was probably happening was webpack was picking those up, rather than the ones output by the loaders. Lesson learned, hopefully this helps someone else.

@bohms27
Copy link

bohms27 commented Nov 8, 2017

I had the issue with the comma missing, but only when there was a comment on the next line.

templateUrl: "foo.html" works fine but ...

templateUrl: "foo.html"
// Test comment
Expects a comma after it.

@nombrekeff
Copy link

Hi,
Any news on this? Im having the same issue here.
My absolute path tempaltes are not beeing replaced by require(...) in the bundle.

@nombrekeff
Copy link

Could not fix it.
I just changed to relative paths... wich is not ideal for big projects as the one I just fixed...
It had over 60 components.
Any news on this would be apreciated.
Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet