Vue-cli: --modern flag fails when chaining "copy" plugin

Created on 17 Sep 2018  路  2Comments  路  Source: vuejs/vue-cli

Version

3.0.3

Reproduction link

https://github.com/scottbedard/vue-cli-bug

Node and OS info

Node 8.9.4, Yarn 1.6.0, Windows 10

Steps to reproduce

Run yarn build:modern

What is expected?

The build should complete with no errors, and static assets should be copied to ./wwwroot

What is actually happening?

The build fails with the following output

$ vue-cli-service build --modern

-  Building legacy bundle for production... ERROR  TypeError: Cannot read property '__expression' of undefined
TypeError: Cannot read property '__expression' of undefined
    at Object.toConfig (C:\git\vue-cli-bug\node_modules\webpack-chain\src\Plugin.js:55:38)
    at clean.Object.assign.plugins.plugins.values.map.plugin (C:\git\vue-cli-bug\node_modules\webpack-chain\src\Config.js:129:61)
    at Array.map (<anonymous>)
    at module.exports.toConfig (C:\git\vue-cli-bug\node_modules\webpack-chain\src\Config.js:129:40)
    at Service.resolveWebpackConfig (C:\git\vue-cli-bug\node_modules\@vue\cli-service\lib\Service.js:218:34)
    at PluginAPI.resolveWebpackConfig (C:\git\vue-cli-bug\node_modules\@vue\cli-service\lib\PluginAPI.js:115:25)
    at module.exports (C:\git\vue-cli-bug\node_modules\@vue\cli-service\lib\commands\build\resolveAppConfig.js:34:25)
    at build (C:\git\vue-cli-bug\node_modules\@vue\cli-service\lib\commands\build\index.js:124:50)
    at api.registerCommand (C:\git\vue-cli-bug\node_modules\@vue\cli-service\lib\commands\build\index.js:50:13)
    at Service.run (C:\git\vue-cli-bug\node_modules\@vue\cli-service\lib\Service.js:203:12)
    at Object.<anonymous> (C:\git\vue-cli-bug\node_modules\@vue\cli-service\bin\vue-cli-service.js:36:9)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
error Command failed with exit code 1.

Building works as expected when the --modern flag is omitted, or when config.plugin('copy') is not called. Configuring other plugins also seems to work as expected.

needs team repro cli-service build

Most helpful comment

in modern mode, the config runs twice, once for legacy, once for modern. We add the copy plugin only to one of those, so that files are only copied once.

solution:

config.plugins.has('copy') && config.plugin('copy').tap(function() {

All 2 comments

Also failing on OSX Version 10.13.5

in modern mode, the config runs twice, once for legacy, once for modern. We add the copy plugin only to one of those, so that files are only copied once.

solution:

config.plugins.has('copy') && config.plugin('copy').tap(function() {
Was this page helpful?
0 / 5 - 0 ratings