electronelectron-builderelectron-vue

npm run build: ValidationError: Invalid options object. Copy Plugin


I'm trying to package an electron app but I'm getting this error:

ValidationError: Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
 - options[0] misses the property 'patterns'. Should be:
   [non-empty string | object { from, to?, context?, globOptions?, toType?, force?, flatten?, transform?, cacheTransform?, transformPath?, noErrorOnMissing? }, ...] (should not have fewer than 1 item)
    at validate (C:\Users\julis\Documents\prescription-data-entry-system\pdes\node_modules\copy-webpack-plugin\node_modules\schema-utils\dist\validate.js:96:11)
    at new CopyPlugin (C:\Users\julis\Documents\prescription-data-entry-system\pdes\node_modules\copy-webpack-plugin\dist\index.js:24:30)
    at Object.<anonymous> (C:\Users\julis\Documents\prescription-data-entry-system\pdes\.electron-vue\webpack.renderer.config.js:181:5)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\Users\julis\Documents\prescription-data-entry-system\pdes\.electron-vue\build.js:14:24)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  name: 'ValidationError',
  errors: [
    {
      keyword: 'required',
      dataPath: '[0]',
      schemaPath: '#/required',
      params: [Object],
      message: "should have required property 'patterns'",
      schema: [Object],
      parentSchema: [Object],
      data: [Object],
      children: [Array]
    }
  ],
  schema: {
    definitions: { ObjectPattern: [Object], StringPattern: [Object] },
    type: 'object',
    additionalProperties: false,
    properties: { patterns: [Object], options: [Object] },
    required: [ 'patterns' ]
  },
  headerName: 'Copy Plugin',
  baseDataPath: 'options',
  postFormatter: null,
  message: 'Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.\n' +
    " - options[0] misses the property 'patterns'. Should be:\n" +
    '   [non-empty string | object { from, to?, context?, globOptions?, toType?, force?, flatten?, transform?, cacheTransform?, transformPath?, noErrorOnMissing? }, ...] (should not have fewer than 1 item)'
}

In .electron-vue\webpack.renderer.config.js, I have:

new CopyWebpackPlugin([
  {
    from: path.join(__dirname, '../static'),
    to: path.join(__dirname, '../dist/electron/static'),
    ignore: ['.*']
  }
]),

And changing it to below, doesn't resolve the error:

    new CopyWebpackPlugin({

      patterns: [
        { from: path.join(__dirname, '../static'), to: path.join(__dirname, '../dist/electron/static') },
      ],

    }),

I'm not sure what the new pattern should be. I've looked at this question and tried to follow that pattern but that didn't work. How can I fix this?


Solution

  • I had to change the same thing in .electron-vue\webpack.web.config.js

    /**
     * Adjust webConfig for production settings
     */
    if (process.env.NODE_ENV === 'production') {
      webConfig.devtool = ''
    
      webConfig.plugins.push(
        new MinifyPlugin(),
        new CopyWebpackPlugin({
          //this is the new change
          patterns: [
            { from: path.join(__dirname, '../static'), to: path.join(__dirname, '../dist/electron/static') },
          ],
    
        }),
        new webpack.DefinePlugin({
          'process.env.NODE_ENV': '"production"'
        }),
        new webpack.LoaderOptionsPlugin({
          minimize: true
        })
      )
    }