meteor-webpack icon indicating copy to clipboard operation
meteor-webpack copied to clipboard

Cannot read property 'getSourceHash' of undefined

Open ssilve1989 opened this issue 7 years ago • 6 comments

Hi

When trying to make a production build using the following command WEBPACK_CONFIG_FILE=\"webpack.prod.js\" meteor build --architecture=os.linux.x86_64 --allow-superuser --directory .build I get the following error:

Errors prevented bundling:
While processing files with ardatan:webpack (for target web.browser):
packages/webpack_plugin.js:74:43: Cannot read property 'getSourceHash' of undefined (at Object.processFilesForTarget)

While processing files with ardatan:webpack (for target os.linux.x86_64):
packages/webpack_plugin.js:74:43: Cannot read property 'getSourceHash' of undefined (at Object.processFilesForTarget)

I assume its printing twice, one for each bundle, client/server

My webpack configs are pretty simple:

// webpack.common.js
const meteorExternals = require('webpack-meteor-externals');
const path = require('path');
const TsConfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

module.exports = {
  devtool: 'cheap-module-source-map',
  resolve: {
    extensions: ['.json', '.js', '.jsx', '.ts', '.tsx'],
    alias: {
      tests: path.resolve(__dirname, 'tests'),
      '/imports': path.resolve(__dirname, 'imports'),
      imports: path.resolve(__dirname, 'imports'),
    },
    plugins: [
      new TsConfigPathsPlugin({
        configFile: path.resolve(__dirname, 'tsconfig.json'),
      }),
    ],
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        use: 'babel-loader?cacheDirectory',
        exclude: /node_modules/,
      },
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  externals: [meteorExternals()],
};
// webpack.prod.js
const merge = require('webpack-merge');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');

const webpackCommon = require('./webpack.common');

const clientConfig = merge(webpackCommon, {
  devtool: 'sourcemap',
  entry: [path.resolve(__dirname, 'client', 'main')],
  mode: 'production',
  module: {
    rules: [
      {
        test: /\.scss/,
        use: ['style-loader', 'css-loader', 'sass-loader'],
      },
      {
        test: /\.css/,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './client/main.html',
    }),
    new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') }),
  ],
});

const serverConfig = merge(webpackCommon, {
  devtool: 'sourcemap',
  mode: 'production',
  entry: path.resolve(__dirname, 'server'),
  target: 'node',
});

module.exports = [clientConfig, serverConfig];

ssilve1989 avatar May 29 '18 13:05 ssilve1989

This looks like a problem with WEBPACK_CONFIG_FILE is that not the correct way to specify a different file?

ssilve1989 avatar May 29 '18 18:05 ssilve1989

you can clone ardatan:webpack into a packages folder in your app and then debug this line

if you still can't find the problem - upload a simple repo to github that produces that error and i'll try it

rGiladi avatar May 29 '18 18:05 rGiladi

It will be fixed in the next release, so you can use default webpack configuration name and environment variables for detection of production mode as a current workaround.

ardatan avatar Jun 03 '18 19:06 ardatan

hi @ardatan, is there something I can do to help releasing a new version with this fix?

onhate avatar Jun 14 '19 19:06 onhate

I came across this bug yesterday, the problem is with how you're specifying the webpack config, it shouldn't have quotes:

WEBPACK_CONFIG_FILE=webpack.prod.js

powderham avatar Jun 19 '19 12:06 powderham

Make sure that there is a line in the .meteorignore file: !webpack.prod.js

atomoc avatar Jan 03 '20 11:01 atomoc