bleenco / ngx-uploader

Angular File Uploader
https://ngx-uploader.jankuri.me
MIT License
757 stars 349 forks source link

Typescript emitted no output when webpack is loading 'ng2-uploader' from node_modules #157

Closed tanvirshuvo closed 7 years ago

tanvirshuvo commented 7 years ago

I have an Angular2 project wrapped up with Webpack 2.1.~ . I have installed ng2-uploader from npm packages and it's now there under node_modules. Now, while I am starting the application I am getting this error:

"Typescript emitted no output for (..path\ng-file-select.ts) at Object.loader (path\node_modules\ts-loader..)"

"Typescript emitted no output for (..path\ng2-uploader.ts) at Object.loader (path\node_modules\ts-loader..)"

"Typescript emitted no output for (..path\ng-file-drop.ts) at Object.loader (path\node_modules\ts-loader..)"

Is this an issue with typescript loader?

Webpack is compiling the ts files into js and the error is getting out from this part of the index.js of ng2-uploader:

 if (outputText == null)
        throw new Error("Typescript emitted no output for " + filePath);

Here is my tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es5"
    ],
    "module": "commonjs",
    "noEmitHelpers": true,
    "removeComments": true,
    "sourceMap": true,
    "target": "es5",
    "types": [
      "core-js",
      "firebase",
      "jasmine",
      "node"
    ]
  },

  "exclude": [
    "node_modules",
    "target",
    "tmp"
  ]
}

Here is my webpack.config.json:

const argv = require('yargs').argv;
const path = require('path');

const autoprefixer = require('autoprefixer');
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
const WebpackMd5Hash = require('webpack-md5-hash');

//=========================================================
//  ENVIRONMENT VARS
//---------------------------------------------------------
const NODE_ENV = process.env.NODE_ENV;

const ENV_DEVELOPMENT = NODE_ENV === 'development';
const ENV_PRODUCTION = NODE_ENV === 'production';
const ENV_TEST = NODE_ENV === 'test';

const HOST = '0.0.0.0';
const PORT = 3000;

//=========================================================
//  LOADERS
//---------------------------------------------------------
const loaders = {
  componentStyles: {
    test: /\.scss$/,
    loader: 'raw!postcss!sass',
    exclude: path.resolve('src/common/styles')
  },
  sharedStyles: {
    test: /\.scss$/,
    loader: 'style!css!postcss!sass',
    include: path.resolve('src/common/styles')
  },
  html: {
    test: /\.html$/,
    loader: 'raw'
  },
  typescript: {
    test: /\.ts$/,
    loader: 'ts',

  }
};

//=========================================================
//  CONFIG
//---------------------------------------------------------
const config = module.exports = {};

config.resolve = {
  extensions: ['.ts', '.js'],
  modules: [
    path.resolve('.'),
    'node_modules'
  ]
};

config.module = {
  loaders: [
    loaders.typescript,
    loaders.html,
    loaders.componentStyles
  ]
};

config.plugins = [
  new DefinePlugin({
    'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
  }),
  new LoaderOptionsPlugin({
    debug: false,
    minimize: ENV_PRODUCTION
  }),

  // Fix for angular2 critical dependency warning
  // https://github.com/r-park/todo-angular2-firebase/issues/96
  new ContextReplacementPlugin(
    // The (\\|\/) piece accounts for path separators in *nix and Windows
    /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
    path.resolve('src')
  )
];

config.postcss = [
  autoprefixer({ browsers: ['last 3 versions'] })
];

config.sassLoader = {
  outputStyle: 'compressed',
  precision: 10,
  sourceComments: false
};

//=====================================
//  DEVELOPMENT or PRODUCTION
//-------------------------------------
if (ENV_DEVELOPMENT || ENV_PRODUCTION) {
  config.entry = {
    main: ['./src/main.ts'],
    polyfills: './src/polyfills.ts',
    vendor: './src/vendor.ts'
  };

  config.output = {
    filename: '[name].js',
    path: path.resolve('./target'),
    publicPath: '/'
  };

  config.plugins.push(
    new CommonsChunkPlugin({
      name: ['vendor', 'polyfills'],
      minChunks: Infinity
    }),
    new HtmlWebpackPlugin({
      chunkSortMode: 'dependency',
      filename: 'index.html',
      hash: false,
      inject: 'body',
      template: './src/index.html'
    })

  );

}

//=====================================
//  DEVELOPMENT
//-------------------------------------
if (ENV_DEVELOPMENT) {
  config.devtool = 'cheap-module-source-map';

  config.module.loaders.push(loaders.sharedStyles);

  config.plugins.push(new ProgressPlugin());

  config.devServer = {
    contentBase: './src',
    historyApiFallback: true,
    host: HOST,
    port: PORT,
    stats: {
      cached: true,
      cachedAssets: true,
      chunks: true,
      chunkModules: false,
      colors: true,
      hash: false,
      reasons: true,
      timings: true,
      version: false
    }
  };
}

//=====================================
//  PRODUCTION
//-------------------------------------
if (ENV_PRODUCTION) {
  config.devtool = 'source-map';

  config.output.filename = '[name].[chunkhash].js';

  config.module.loaders.push({
    test: /\.scss$/,
    loader: ExtractTextPlugin.extract('css?-autoprefixer!postcss!sass'),
    include: path.resolve('src/common/styles')
  });

  config.plugins.push(
    new WebpackMd5Hash(),
    new ExtractTextPlugin('styles.[contenthash].css'),
    // TODO: DedupePlugin is broken on webpack2-beta22
    // new webpack.optimize.DedupePlugin(),
    new UglifyJsPlugin({
      comments: false,
      compress: {
        dead_code: true, // eslint-disable-line camelcase
        screw_ie8: true, // eslint-disable-line camelcase
        unused: true,
        warnings: false
      },
      mangle: {
        screw_ie8: true  // eslint-disable-line camelcase
      }
    })
  );
}

//=====================================
//  TEST
//-------------------------------------
if (ENV_TEST) {
  config.devtool = 'inline-source-map';

  config.module.loaders.push(loaders.sharedStyles);

  if (argv.coverage) {
    config.module.postLoaders = [{
      test: /\.ts$/,
      loader: 'istanbul-instrumenter-loader',
      include: path.resolve('src'),
      exclude: [
        /\.spec\.ts$/,

      ]
    }];

    // override tsconfig.json
    config.ts = {
      compilerOptions: {
        inlineSourceMap: true,
        sourceMap: false
      }
    };
  }
}

What is wrong, and how can I fix this?

jmarc-roy commented 7 years ago

Hi @tanvirshuvo, I had the same issue, I fix it by using 'awesome-typescript-loader' (https://www.npmjs.com/package/awesome-typescript-loader) rather than 'ts-loader'. Hope it help!