4

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
10
  • @BobSponge Yes, looks like that is the case Commented Mar 20, 2016 at 9:14
  • Try to change devtool to hidden-source-map: devtool: "hidden-source-map" Commented Mar 20, 2016 at 9:20
  • @BobSponge nope, the issue remains. Commented Mar 20, 2016 at 9:23
  • Okay, next try. Disable source-map generation for ts-files in tsconfig: "sourceMap": false and "inlineSourceMap": false in compiler options ( github.com/s-panferov/awesome-typescript-loader#tsconfigjson ) Commented Mar 20, 2016 at 9:41
  • @BobSponge same... Commented Mar 20, 2016 at 9:47

1 Answer 1

11

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')
        ]
      }
    ]
    ...
  }
  ...
};
Sign up to request clarification or add additional context in comments.

6 Comments

how to fix in webpack.dev.js file? Mine run in webpack dev enviroment and I dont know where to fix, here is my webpack.dev.js file: pastie.org/10875854
You shouldn't need to if your webpack.common.js file has this since you're using webpackMerge to pull in those settings.
No, it will run in webpack.dev.js. Here is my webpack.config.js, since my NODE_ENV is dev, it will run my webpack.dev.js pastie.org/10877975
Gotcha, but in your dev file you are merging the configuration values from the common config file. See line: module.exports = webpackMerge(commonConfig, {...
if you run into issues with helpers.root - use this instead....path.join(process.cwd(), "node_modules\\primeng"),
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.