vuejs / vue-cli

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

vue-cli-service: not found inside Docker #5107

Closed fd008 closed 4 years ago

fd008 commented 4 years ago

Version

4.1.2

Reproduction link

https://github.com/engblh/docker-for-vue-dev

Environment info

Environment Info:

  System:
    OS: Linux 4.19 Debian GNU/Linux 9 (stretch) 9 (stretch)
    CPU: (2) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
  Binaries:
    Node: 10.15.0 - /usr/local/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.13.6 - /usr/local/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
  npmGlobalPackages:
    @vue/cli: 4.1.2

Steps to reproduce

  1. Git clone
  2. cd docker-for-vue-dev
  3. Docker-compose up

Environment used:

docker version 2.2.0.0(42247) win 10 and WSL ubuntu 18.04

Docker engine 19.03.5, compose v1.25.2

What is expected?

expected to show default vue homepage

What is actually happening?

Successfully built 4166371f2e1a Successfully tagged docker-vue:latest Creating docker-vue ... done Attaching to docker-vue docker-vue | docker-vue | > docker-for-vue-dev@0.1.0 serve /var/www/docker-vue docker-vue | > vue-cli-service serve docker-vue | docker-vue | sh: 1: vue-cli-service: not found docker-vue | npm ERR! file sh docker-vue | npm ERR! code ELIFECYCLE docker-vue | npm ERR! errno ENOENT docker-vue | npm ERR! syscall spawn docker-vue | npm ERR! docker-for-vue-dev@0.1.0 serve: vue-cli-service serve docker-vue | npm ERR! spawn ENOENT docker-vue | npm ERR! docker-vue | npm ERR! Failed at the docker-for-vue-dev@0.1.0 serve script. docker-vue | npm ERR! This is probably not a problem with npm. There is likely additional logging output above. docker-vue | docker-vue | npm ERR! A complete log of this run can be found in: docker-vue | npm ERR! /root/.npm/_logs/2020-01-24T15_45_29_935Z-debug.log


It was working a couple days ago on win 10, WSL ubuntu 18.04, but problem started happening since yesterday.

It works on MacOS, but not on Win 10, WSL Ubuntu 18.04

levifarley commented 4 years ago

Also having this exact same issue right now. It works in Docker on macOS, but not Docker on Windows. But if I start the container through docker and attach shell to it and run vue-cli -v it recognizes it is installed.

If it makes any difference, a buddy was able to get the exact same repo/dockerfile working first try on his Windows 10 machine. 🤷‍♂ So its not Docker for Windows wide, but a problem with our individual PCs. As to what the problem is, I have no clue.

sakinah-github commented 4 years ago

Also having this exact same issue right now. It works in Docker on macOS, but not Docker on Windows. But if I start the container through docker and attach shell to it and run vue-cli -v it recognizes it is installed.

Running that command didn't work for me in my docker-compose command. It would just say: sh: 1: vue-cli: not found. Running @vue/cli -v also says the same. Even running vue --version says not found.

Strangely enough, if I have npm install locally on my own project, and then use docker to serve (using a pre-existing container). It will get pass those issues but the brick wall I hit is the docker's node_modules' node-sass isn't based on linux's (what the docker's environment based of), it's based on Window's environment... my local build. The container does not shut down by this error, so getting inside the docker container and running npm rebuild node-sass would download the correct node-sass, then restarting the container works.

...Removing my local node-modules (cut and paste it outside the project), and running serve again with docker would get vue-cli-service: not found. But if I switch the npm run serve with ls node-modules in my docker-compose's command, I will find docker still has its own node-modules packages installed as it should, due to anonymous volume setup on the node_modules in the docker-compose yml.

All I can say, I'm very confused what's going on. Is anonymous volume working properly? When docker builds the image, is it installing the packages properly? I suspect something went wrong in the installing, since in a fresh clean project without a local installed node-modules, the vue docker instance does not recognize any vue or vue cli's commands when I try to run it through docker-compose command or CMD in dockerfile (although RUN works but I won't be able to get out of the building stage).

levifarley commented 4 years ago

@camper6 I think i'm having a similar issue as you. If my Dockerfile has RUN npm install and I build the image, it shows npm installs everything successfully. Then when I run docker run -v ${PWD}:/app -v /app/node_modules -p 3000:8080 --rm app:test it dies immediately with error sh: vue-cli-service: not found.

So I'll tell you what I have tried.

I've about exhausted everything I can think of right now.

tjeerddie commented 4 years ago

I have the same problem, haven't found a way to fix vue-cli-service not found with npm. I did find a way to serve vue using this hacky command which runs it directly from within node_modules: node /node_modules/@vue/cli-service/bin/vue-cli-service.js serve

levifarley commented 4 years ago

It seems npm install isn't actually installing dependencies, or they are getting overritten when you start the container so the node_modules directory is empty causing the issue. The only work around I figured out was to remove the RUN npm install from the Dockerfile, and just start the container up and attach a shell to it and run npm install manually, then it works properly.

Downside is that you have to run npm install every time that you start the container. Upside is that your dependencies always stay up to date and its finally usable. Seems like the problem for me is just on Docker for Windows, as I don't experience the same problem on MacOS.

bitburnerz commented 4 years ago

Same here. When I mount src in a Windows folder npm install doesn't populate node_modules correctly and vue-cli-service does not exist.

haoqunjiang commented 4 years ago

Considering this issue does not happen on macOS, this might be a bug in Docker for Windows. And the most recent release notes cited a lot of volume-related bugs (https://docs.docker.com/docker-for-windows/release-notes/), would you please upgrade Docker for Windows to the latest and try again?

bitburnerz commented 4 years ago

I found my problem. I was inadvertently setting NODE_ENV to production in my docker-compose so all NPM dev dependencies (including vue-cli-service) were not being installed.

appleboy commented 4 years ago

We need to separate the CI/CD flow as below:

steps:
- name: install
  image: node:13
  commands:
  - npm install

- name: build
  image: node:13
  environment:
    NODE_ENV: production
  commands:
  - npm run build
bitsofinfo commented 4 years ago

same issue, in builds in Kaniko

Azurox commented 4 years ago

Hi everyone, same error on my server with node_env set as production, removing it or installing all dependecies with --only=dev works but its dam ugly.
I don't know what is the final word on this, if @vue/cli-service is mandatory to build, why is it in devDepencies ? Is installing @vue/cli as a global npm depency on a production server really a good solution ? Multiple people seems to have the same problem #2404 and there seems to be no final word on this

haoqunjiang commented 4 years ago

Production means only the built bundle is to serve.

haoqunjiang commented 4 years ago

Pre-configured NODE_ENV is meaningful only when there's a Node.js server to run.

In the context of Vue.js apps, it's for server-side rendering or static assets hosting.

For a production Node.js server, you won't need any of the src/* stuff and they should never be pushed to a production server.


The bundles should be built in the CI/CD pipeline. You should not pre-configure NODE_ENV in these servers. Because by definition, they need to:


So in conclusion: NODE_ENV should be set on the fly for any tasks except for the real production servers. And @vue/cli-service is not meant to be used in that kind of server.

BenjaminGuillot commented 4 years ago

Same issue. This post work for me ;) Thx @sodatea

amaurybrisou commented 3 years ago

In Github Actions docker I had the issue even in NODE_ENV=development.

A quick fix that did work for me is to install @vue/cli-service globally with this command npm install -g @vue/cli-service

yoannes commented 3 years ago

This approach didn't work for me, I get code EACCES error.

So far I can only deploy using firebase cli, Github actions is not working

In Github Actions docker I had the issue even in NODE_ENV=development.

A quick fix that did work for me is to install @vue/cli-service globally with this command npm install -g @vue/cli-service

tinchox5 commented 3 years ago

This issue worked for me: https://github.com/vuejs/vue-cli/issues/3506

tperrelli commented 1 year ago

npm install -g @vue/cli-service is a odd solution. I was getting the same issue but realized that devDependencieswasn't being installed. For some reason, container's ENV was set to production as default.

So, this is what I've done to get this resolved the right way:

In Dockerfile...

NODE_ENV=development npm install