Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding webpack plugin in chainWebpack mode failed #1729

Closed
MarvinXu opened this issue Jul 2, 2018 · 8 comments

Comments

@MarvinXu
Copy link
Contributor

@MarvinXu MarvinXu commented Jul 2, 2018

Version

3.0.0-rc.3

Reproduction link

MarvinXu/vue-cli-mpa-test@c591575

Steps to reproduce

https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-plugin

module.exports = {
  chainWebpack: config => {
    config
      .plugin('html')
      .tap(args => {
        args[0].template = '/Users/username/proj/app/templates/index.html'
        return args
      })
  }
}

npm run serve

What is expected?

no error

What is actually happening?

TypeError: Cannot read property '__expression' of undefined

@LinusBorg

This comment has been minimized.

Copy link
Member

@LinusBorg LinusBorg commented Jul 3, 2018

Will take a look tonight, can't really imagine this is broken

@MarvinXu

This comment has been minimized.

Copy link
Contributor Author

@MarvinXu MarvinXu commented Jul 3, 2018

I tested it again on my home pc, broke still.
win7 ; npm5.6.0;
reproduction steps:

  1. vue create myproject
  2. add vue.config.js
module.exports = {
  chainWebpack: config => {
    config
      .plugin('html')
      .tap(args => {
        return args
      })
  }
}
  1. npm run serve
@LinusBorg

This comment has been minimized.

Copy link
Member

@LinusBorg LinusBorg commented Jul 3, 2018

a freshly created project builds fine for me:

image

OS / Node version / npm version ?

Can you share the full stack trace of the error? which module does this error come from?

@LinusBorg

This comment has been minimized.

Copy link
Member

@LinusBorg LinusBorg commented Jul 3, 2018

Ok, your own project fails. But now I realize you are using the "pages" feature.

See the docs here: https://cli.vuejs.org/config/#pages

TIP

When building in multi-page mode, the webpack config will contain different plugins (there will be multiple instances of html-webpack-plugin and preload-webpack-plugin). Make sure to run vue inspect if you are trying to modify the options for those plugins.

In other words: since you are using the pages option, there's no plugin called html.

Thorstens-MacBook-Pro:vue-cli-mpa-test thorsten$ vue inspect --plugins
[
  'vue-loader',
  'define',
  'case-sensitive-paths',
  'friendly-errors',
  'hmr',
  'no-emit-on-errors',
  'progress',
  'html-index',
  'html-subpage',
  'preload-index',
  'prefetch-index',
  'preload-subpage',
  'prefetch-subpage',
  'copy'
]

You might have to just each of those for whatever you want to do.

@MarvinXu

This comment has been minimized.

Copy link
Contributor Author

@MarvinXu MarvinXu commented Jul 3, 2018

My bad, forgot the "minimal reproduction" basic... Thanks!

@jinwyp

This comment has been minimized.

Copy link

@jinwyp jinwyp commented Oct 18, 2018

Thanks @LinusBorg .

@stephanepericat

This comment has been minimized.

Copy link

@stephanepericat stephanepericat commented Nov 29, 2018

vue inspect --plugins
[
  'vue-loader',
  'define',
  'case-sensitive-paths',
  'friendly-errors',
  'hmr',
  'no-emit-on-errors',
  'progress',
  'html',
  'preload',
  'prefetch'
]

I get the same issue, here is my list of plugins...

looks like calling "config.plugin()" causes this error no matter what option you overwrite

@LinusBorg

This comment has been minimized.

Copy link
Member

@LinusBorg LinusBorg commented Nov 29, 2018

You might have the same symptom, but appearantly are nor using the pages feature, so your automation a different.

Hence:

Open an issue and provide a reproduction.

This issue is resolved and closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.