vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.75k stars 6.33k forks source link

"Cannot find module '@vue/cli-service/...' from ..." when create project with remote preset that edited existing templates #5965

Open Leesson opened 4 years ago

Leesson commented 4 years ago

Version

4.5.7

Reproduction link

https://github.com/Leesson/vue-cli-preset-sim

Environment info

Environment Info:

  System:
    OS: macOS 10.15.7
    CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
  Binaries:
    Node: 10.12.0 - ~/.nvm/versions/node/v10.12.0/bin/node
    Yarn: Not Found
    npm: 6.14.5 - ~/.nvm/versions/node/v10.12.0/bin/npm
  Browsers:
    Chrome: 86.0.4240.80
    Edge: Not Found
    Firefox: Not Found
    Safari: 14.0
  npmPackages:
    @vue/cli-overlay:  4.5.7 
    @vue/cli-plugin-router:  4.5.7 
    @vue/cli-plugin-vuex:  4.5.7 
    @vue/cli-service: ^4.5.7 => 4.5.7 
    @vue/cli-shared-utils:  4.5.7 
    @vue/component-compiler-utils:  3.2.0 
    @vue/preload-webpack-plugin:  1.1.2 
    @vue/web-component-wrapper:  1.2.0 
    vue-hot-reload-api:  2.3.4 
    vue-loader:  15.9.3 (16.0.0-beta.8)
    vue-style-loader:  4.1.2 
    vue-template-es2015-compiler:  1.9.1 
  npmGlobalPackages:
    @vue/cli: 4.5.7

Steps to reproduce

create a project with this preset:

vue create --preset Leesson/vue-cli-preset-sim#main project-name

and then there will be an error "Error: Cannot find module '@vue/cli-service/generator/template/public/index.html' from '/private/var/folders/.../vue-cli-presets/vue-cli-preset-sim/generator/template/public'"

It seems the cli should install dependencies after clone the preset repo to local. you can clone this repo to local, install it, and run the code below:

vue create --preset /path/to/repo project-name

then you can get the right result

What is expected?

create project

What is actually happening?

throw an error

steveworkman commented 4 years ago

👍 Looking forward to this landing. I find it odd that the docs suggest to do this in JS https://cli.vuejs.org/dev-guide/plugin-dev.html#changing-main-file

Is it that there are two ways (one being broken) and the other way is just complicated?

fangbinwei commented 4 years ago

@steveworkman Some plugins need to modify files conditionally such as vue-cli-plugin-vue-next, so it should do like change-main-file in official doc. Else extend template is not powerful, it is usually used to create file when init a new project.