angular2-template-loader icon indicating copy to clipboard operation
angular2-template-loader copied to clipboard

404 when loading templates from npm linked dependencies

Open alvaro9210 opened this issue 8 years ago • 4 comments
trafficstars

I am currently developing an Angular 2 project (Let's call it Workbench) which dependes on another Angular 2 project (Let's call it Panel). Panel provides of a lot of components which are then used in Workbench. At the same time I am developing Workbench, I make changes to Panel, so I need to view the changes immediately and that's why I linked the dependency with npm link ( npm link ../panel/dist) and after that Panel is being found by my bundler (Webpack 2) and its bundled correctly. Until here everything works fine, the problem comes when the browser loads the Workbench app because it doesn't find the templates of the components provided by the Panel component, it throws a 404 - Error Message. Here's a screenshot of the error messages: screen shot 2017-02-02 at 10 08 56 am

As you can see, the angular2-template-loader is trying to resolve the templates by going to the src folder of the Workbench app, not the panel app. (http://127.0.0.1:8080/src/header.component.html)

Here's how I import the templates and styles of the components of Panel.

@Component( {
	selector: "cp-header",
	templateUrl: "./header.component.html",
	styleUrls: [ "./header.component.scss" ],
	host: {
		class: "ui navigation inverted menu"
	}
} )

screen shot 2017-02-02 at 10 12 04 am

And these are the Webpack rules for resolving file extensions:

module: {
  rules: [
    {
      test: /\.ts$/,
      use: [ "awesome-typescript-loader", "angular2-template-loader", "angular-router-loader" ]
    },
    {
      test: /\.json$/,
      use: "json-loader"
    },
    {
      test: /\.html$/,
      use: "raw-loader"
    },
    {
      test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
      use: "file-loader?name=assets/[name].[hash].[ext]"
    },
    {
      test: /\.css$/,
      use: [ "style-loader", "css-loader" ],
      include: [ helpers.root( "src", "styles" ) ]
    },
    {
      test: /\.scss$/,
      exclude: /node_modules/,
      use: [ "raw-loader", "sass-loader" ],
      // use: [ "style-loader", "css-loader", "sass-loader" ],
    },
  ]
},

Is it possible to have linked packages using angular2-template-loader?

alvaro9210 avatar Feb 02 '17 16:02 alvaro9210

Hello, I have the same problem with loading component templates on version 0.6.1 version (pushed 2 hours ago) and I downgraded to 0.6.0 and locked it and problem fixed. Note: I'm using html-loader instead of raw-loader.

 {
      test: /\.html$/,
      use: "html-loader"
    },

kharrak avatar Feb 05 '17 17:02 kharrak

Hi - I seem to be having the exact same issue with my components, I locked the version to 0.6.0 for now :)

Gbuomprisco avatar Feb 06 '17 00:02 Gbuomprisco

Same problem in one of our projects.

kgjersda avatar Feb 06 '17 14:02 kgjersda

+1 qq 20170207005117

keyiis avatar Feb 06 '17 16:02 keyiis