1

This is how I am trying to make webpack copy the JSON files in locales folder present at the root level of the project.

  config.plugins.push(
    new CopyPlugin({
      patterns: [
        {
          from: "./locales",
          to: "./",
        },
      ],
    }),
    new webpack.DefinePlugin({
      "process.env.NODE_ENV": JSON.stringify(
        (env && env.NODE_ENV) || "production"
      ),
    })
  );

I get the following error

D:\aakashverma\BVC\hello-ps-bvc-addon\addon\src\main\assets\node_modules\webpack\bin\webpack.js:348
                        throw err;
                        ^

TypeError: Cannot read property 'thisCompilation' of undefined
    at CopyPlugin.apply (D:\aakashverma\BVC\hello-ps-bvc-addon\addon\src\main\assets\node_modules\copy-webpack-plugin\dist\index.js:457:20)
    at Compiler.apply (D:\aakashverma\BVC\hello-ps-bvc-addon\addon\src\main\assets\node_modules\tapable\lib\Tapable.js:375:16)
    at webpack (D:\aakashverma\BVC\hello-ps-bvc-addon\addon\src\main\assets\node_modules\webpack\lib\webpack.js:33:19)
    at processOptions (D:\aakashverma\BVC\hello-ps-bvc-addon\addon\src\main\assets\node_modules\webpack\bin\webpack.js:335:15)
    at D:\aakashverma\BVC\hello-ps-bvc-addon\addon\src\main\assets\node_modules\webpack\bin\webpack.js:397:2
    at Object.Yargs.self.parse (D:\aakashverma\BVC\hello-ps-bvc-addon\addon\src\main\assets\node_modules\webpack\node_modules\yargs\yargs.js:533:18)
    at Object.<anonymous> (D:\aakashverma\BVC\hello-ps-bvc-addon\addon\src\main\assets\node_modules\webpack\bin\webpack.js:152:7)

I cleaned up and reinstalled node_modules but still no progress.

Kindly help.

EDIT: Added package.json below

  "dependencies": {
    "@material-ui/core": "^4.11.1",
    "@reduxjs/toolkit": "^1.4.0",
    "flatted": "^3.1.0",
    "gql-query-builder": "^3.5.0",
    "i18next": "^19.8.4",
    "i18next-http-backend": "^1.0.21",
    "ps-solution-library-ui-common": "^1.7.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-i18next": "^11.8.5",
    "react-redux": "^7.2.1",
    "react-resize-aware": "^2.7.2",
    "react-router": "^5.2.0",
    "react-router-dom": "^5.2.0",
    "redux": "^4.0.5",
    "redux-form": "^8.3.6",
    "redux-form-validators": "^3.0.1"
  },
  "devDependencies": {
    "babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
    "babel-plugin-transform-es3-property-literals": "^6.22.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "copyfiles": "^2.4.1",
    "html-webpack-externals-plugin": "^3.8.0",
    "ps-solution-library-webpack-common": "^1.0.2",
    "uglifyjs-webpack-plugin": "^2.2.0"
  },
Aakash Verma
  • 3,705
  • 5
  • 29
  • 66
  • Can you share you package.json? – tmhao2005 Jan 12 '21 at 16:46
  • @tmhao2005 done. I guess it's a mismatch between the webpack and webpack-dev-server versions somewhere down in my sub-dependency chain for the common ui lib that I am using. – Aakash Verma Jan 12 '21 at 17:18
  • I don't see `webpack` & `webpack-copy-plugin` installed locally. Not sure why is that? – tmhao2005 Jan 13 '21 at 02:49
  • @tmhao2005 they're coming as sub-dependencies from `ps-solution-library-webpack-common`. I tried installing my own regardless but it didn't help. – Aakash Verma Jan 13 '21 at 10:34
  • I tested my end with both v4/5 of webpack but it worked well. If you can post your repo which you added webpack locally then I could look at it for you – tmhao2005 Jan 13 '21 at 10:44

0 Answers0