modify-source-webpack-plugin icon indicating copy to clipboard operation
modify-source-webpack-plugin copied to clipboard

crash when build again

Open dreamerblue opened this issue 4 years ago • 2 comments

version: 3.0.0-rc.0

webpack version: 4.46.0

When i use this plugin, the first time build is successful, but if i modify some source code and run build again (with node_modules/.cache), it will throw error. Here is output:

 error  in ./src/views/Home.vue?vue&type=script&lang=ts&

Syntax Error: Thread Loader (Worker 0)
Modify function at index 0 is not defined in global space.


 @ ./src/views/Home.vue?vue&type=script&lang=ts& 1:0-560 1:576-579 1:581-1138 1:581-1138
 @ ./src/views/Home.vue
 @ ./src/views lazy ^\.\/.*$ namespace object
 @ ./src/router/index.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

I think it's caused by cache. If i remove node_modules/.cache, it can build successfully again.

I am using a new template project (Vue 2) created buy vue-cli. Here is my vue.config.js:

const { ModifySourcePlugin } = require('modify-source-webpack-plugin');

module.exports = {
  configureWebpack: {
    plugins: [
      new ModifySourcePlugin({
        debug: true,
        rules: [
          {
            test: /\.vue\?vue&type=script.*/,
            modify: (src, path) => {
              console.log('modify');
              var s = '\n\n';
              return src + s;
            },
          },
        ],
      }),
    ],
  },
};

dreamerblue avatar Nov 28 '21 04:11 dreamerblue

I'm preparing changes which should help you with this bug. Keep updated

artembatura avatar Dec 17 '21 20:12 artembatura

Also thank you for reporting this, after investigating I understand that it's a serious bug which can cause to be plugin fully useless. Found and other smaller bug...

artembatura avatar Dec 17 '21 21:12 artembatura

This issue was fixed in the last plugin version (v4). Please look at migration guide because it has a new breaking API

artembatura avatar Feb 11 '23 15:02 artembatura