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

Strange issue when using webpack 2 #957

Open
faceleg opened this issue Jan 17, 2017 · 11 comments
Open

Strange issue when using webpack 2 #957

faceleg opened this issue Jan 17, 2017 · 11 comments

Comments

@faceleg
Copy link

faceleg commented Jan 17, 2017

Trying to upgrade to webpack 2, my build fails with the following error:

ERROR in ./~/ng-table/src/browser/pager.html Module build failed

Importing library (fails):

import * as ngTable from 'ng-table'

Requiring bundle (success):

require('ng-table/bundles/ng-table.js')

webpack config:

'use strict';

const webpack = require('webpack');
const NgAnnotatePlugin = require('ng-annotate-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const argv = require('yargs').argv;
const path = require('path');

module.exports = {
  watch: false,
  bail: true,
  cache: true,
  devtool: 'source-map',
  entry: './typescript/app/app.ts',
  output: {
    path: path.resolve(__dirname, 'public'),
    filename: 'build/main.bundle.js',
    sourceMapFilename: '[name]-[chunkhash].map'
  },
  resolve: {
    extensions: [
      '.webpack.js',
      '.web.js',
      '.ts',
      '.js'
    ],
    alias: {
      Raven: path.resolve(__dirname, 'node_modules/raven-js/src/raven.js')
    }
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
    }),
    new NgAnnotatePlugin({
      add: true
    }),
    new ExtractTextPlugin('build/[name].css'),
    new HtmlWebpackPlugin({
      filename: 'index.html',
      inject: false,
      hash: true,
      cache: false,
      template: 'ejs-loader!./typescript/index.html',
      locals: {
        environment: ENVIRONMENT,
        production: process.env.PRODUCTION,
        cdnDomain: CDN_DOMAIN,
        backendUrl: BACKEND_URL,
        releaseVersion: RELEASE_VERSION
      }
    }),
    new webpack.SourceMapDevToolPlugin({
      filename: '[file].map', // if no value is provided the sourcemap is inlined
      test: /\.(ts|js)($|\?)/i // process .js and .ts files only
    })
  ],
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: 'awesome-typescript-loader'
      },
      {
        test: /\.p?css$/,
        loader: ExtractTextPlugin.extract({
          fallbackLoader: 'style-loader',
          loader: [
            'css-loader',
            'postcss-loader'
          ]
        })
      },
      {
        test: /\.html$/,
        exclude: /index.html$/,
        use: [
          {
            loader: 'ngtemplate-loader',
            options: {
              relativeTo: path.resolve(__dirname, 'typescript')
            }
          },
          {
            loader: 'html-loader'
          }
        ]
      }
    ]
  },
  devServer: {
    historyApiFallback: true
  }
}
@richtmat
Copy link

@faceleg have you been able to resolve that issue? I'm upgrading an AngularJS 1.5 app to Webpack 2 and see a GET http://app.finderbox.dev/app/ng-table/pager.html 404 (Not Found) in the browser log.

@faceleg
Copy link
Author

faceleg commented Feb 2, 2017

@richtmat no I gave up and have been using webpack 1. Very interested in a solution though

@faceleg faceleg changed the title Strange Strange issue when using webpack 2 Feb 10, 2017
@mheppner
Copy link

I think this might actually be related to ngtemplate-loader when specifying relativeTo. I'm not getting any errors about not finding http://app.finderbox.dev/... though. Might be related: webpack-contrib/html-loader#91. I'm using webpack@2.2.1 and ng-table@3.0.1.

On your test for .html, try removing relativeTo and running Webpack. For me, it compiles fine, and the ng-table templates are added to the cache. Crack open your bundle and check it out.

Since we'll still need a prefix, I'm messing around with having a loader/test block for my app and a separate block for node_modules.

@richtmat
Copy link

@mheppner unfortunately, for me it does not change a thing (here and #969).

Only difference is that local templates are wrong as well. The url ending on .dev is my local development url, you obviously cannot go there.

As I said in #969 , I put the template content of the bundle in my files. The templates are put into the cache like this: $templateCache.put('ng-table/pager.html', html);. I still struggle to find out if its a ng-table or webpack issue...

@LuisUrrutia
Copy link

Up, same error here

@radius
Copy link

radius commented May 25, 2017

Yo, I was able to solve this by changing how I import ng-table into my project. Importing directly from the bundle fixed it for me:

import 'ng-table/bundles/ng-table';

@fedorovsky
Copy link

Works great: import 'ng-table/bundles/ng-table';

@sargue
Copy link

sargue commented Sep 7, 2017

Same problema here. When importing like

import { ngTableModule } from 'ng-table';

then the header and footer are not bundled resulting in a HTTP 404.

Changing the import to

import 'ng-table/bundles/ng-table';

solves the header/footer problem but there's a glitch missing: the ^ and v sorting indicators are not shown. Sorting happens but there is no visual indication.

Any ideas?

@jheimbouch
Copy link

@sargue This is a few months late, but I myself ran into the same problem with the sorting ^ and v not showing.

Add

import 'ng-table/bundles/ng-table.css';

:)

@sargue
Copy link

sargue commented Jan 24, 2018

Thanks @jheimbouch , I can't try it because I'm no longer working on that project. But thanks anyway, I may be useful for somebody else.

@rmunn
Copy link

rmunn commented Oct 5, 2020

I was able to get the HTML files compiling properly with Webpack by putting the following in my webpack.config.js:

    module: {
      rules: [
        // ...
        { test: /ng-table\/.*\.html$/, use: ['ngtemplate-loader?requireAngular&relativeTo=/src/browser/&prefix=ng-table/', 'html-loader'] }
      ]
    }

This also requires the NPM packages ngtemplate-loader and html-loader. Full details: #969 (comment)

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

No branches or pull requests

9 participants