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

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 18 (3 by maintainers)

Most upvoted comments

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.

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.

  • Only the built dist/ bundles are required to run the server-side rendering.
  • Only the built dist/ bundles are to be served in an asset 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:

  • Install all the dev utilities to process the testing, building… This task requires NODE_ENV to be development or empty.
  • Run the unit tests, which requires NODE_ENV to be test.
  • Build the production assets, run E2E tests, which requires NODE_ENV to be production.

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.

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?

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

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.