Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack Angular2 cannot find .ts files from widget library

I am trying to integrate a component library in an angular2/webpack/typescript project.

The library is already transpiled to javascript, however when it is loaded, it looks like webpack is looking for the .ts files instead. Here is the webpack configuration I am using:

module.exports = {
  ......
  entry: {

    'polyfills': './src/polyfills.ts',
    'vendor': './src/vendor.ts',
    'main': './src/main.ts'
  },
  resolve: {
    extensions: ['', '.ts', '.js']
  },
  .....
  module: {
    preLoaders: [
        {test: /\.js$/, loader: 'source-map-loader', exclude: [helpers.root('node_modules/rxjs')]}
    ],
    loaders: [
      {test: /\.ts$/, loader: 'awesome-typescript-loader', exclude: [/\.(spec|e2e)\.ts$/]} ,
      {test: /\.json$/, loader: 'json-loader'},
      {test: /\.css$/, loader: 'raw-loader'},
      {test: /\.html$/, loader: 'raw-loader', exclude: [helpers.root('src/index.html')]}
    ]
  },

  plugins: [
    new ForkCheckerPlugin(),
    new webpack.optimize.OccurenceOrderPlugin(true),
    new webpack.optimize.CommonsChunkPlugin({name: ['main', 'vendor', 'polyfills'], minChunks: Infinity}),
    new CopyWebpackPlugin([{from: 'src/assets', to: 'assets'}]),
    new HtmlWebpackPlugin({template: 'src/index.html', chunksSortMode: 'none'}),
    new webpack.DefinePlugin({'ENV': JSON.stringify(METADATA.ENV), 'HMR': HMR})
  ]  
};

I am running the application in the webpack dev server. Here is the error message:

./~/primeng/components/selectbutton/selectbutton.js
Cannot find source file 'selectbutton.ts': Error: Cannot resolve 'file' or 'directory' ./selectbutton.ts in C:\data\14-03\angular2-webpack-starter\node_modules\primeng\components\selectbutton
like image 467
Bojana Popovska Avatar asked Dec 18 '22 18:12

Bojana Popovska


1 Answers

I was able to solve this error by updating the webpack config to exclude sourcemaps from primeng:

module.exports = {
  ....
  module: {
    preLoaders: [
      ...
      {
        test: /\.js$/,
        loader: 'source-map-loader',
        exclude: [
          helpers.root('node_modules/primeng')
        ]
      }
    ]
    ...
  }
  ...
};
like image 180
Colin Mathews Avatar answered Jan 02 '23 16:01

Colin Mathews