microsoft / vscode-remote-release

Visual Studio Code Remote Development: Open any folder in WSL, in a Docker container, or on a remote machine using SSH and take advantage of VS Code's full feature set.
https://aka.ms/vscode-remote
Other
3.62k stars 277 forks source link

ELIFECYCLE Error when trying to run nodejs tool (Storybook) in typescript-node container #5273

Closed tschanz-pcv closed 3 years ago

tschanz-pcv commented 3 years ago

npm Log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'storybook' ]
2 info using npm@6.14.13
3 info using node@v14.17.0
4 verbose run-script [ 'prestorybook', 'storybook', 'poststorybook' ]
5 info lifecycle PROJ_X@0.1.0~prestorybook: PROJ_X@0.1.0
6 info lifecycle PROJ_X@0.1.0~storybook: PROJ_X@0.1.0
7 verbose lifecycle PROJ_X@0.1.0~storybook: unsafe-perm in lifecycle true
8 verbose lifecycle PROJ_X@0.1.0~storybook: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/workspaces/PROJ_X/node_modules/.bin:/vscode/vscode-server/bin/x64/507ce72a4466fbb27b715c3722558bb15afa9f48/bin:/usr/local/share/npm-global/bin:/usr/local/share/nvm/current/bin:/usr/local/share/npm-global/bin:/usr/local/share/nvm/current/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/node/.local/bin
9 verbose lifecycle PROJ_X@0.1.0~storybook: CWD: /workspaces/PROJ_X
10 silly lifecycle PROJ_X@0.1.0~storybook: Args: [
10 silly lifecycle   '-c',
10 silly lifecycle   'cross-env STORYBOOK_TARGET_FLAVOR=flavor REACT_APP_TARGET_FLAVOR=flavor start-storybook -p 6006 -s public'
10 silly lifecycle ]
11 silly lifecycle PROJ_X@0.1.0~storybook: Returned: code: 1  signal: null
12 info lifecycle PROJ_X@0.1.0~storybook: Failed to exec storybook script
13 verbose stack Error: PROJ_X@0.1.0 storybook: `cross-env STORYBOOK_TARGET_FLAVOR=flavor REACT_APP_TARGET_FLAVOR=flavor start-storybook -p 6006 -s public`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:376:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:376:20)
13 verbose stack     at maybeClose (internal/child_process.js:1055:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid PROJ_X@0.1.0
15 verbose cwd /workspaces/PROJ_X
16 verbose Linux 5.10.25-linuxkit
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "storybook"
18 verbose node v14.17.0
19 verbose npm  v6.14.13
20 error code ELIFECYCLE
21 error errno 1
22 error PROJ_X@0.1.0 storybook: `cross-env STORYBOOK_TARGET_FLAVOR=flavor REACT_APP_TARGET_FLAVOR=flavor start-storybook -p 6006 -s public`
22 error Exit status 1
23 error Failed at the PROJ_X@0.1.0 storybook script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Steps to Reproduce:

  1. Create-React-App Project with Storybook
  2. Open Project in mcr.microsoft.com/vscode/devcontainers/typescript-node:0-14 container
  3. Try to run Storybook with start-storybook -p 6006 -s public
  4. Most of the times the npm process exits before it manages to finish building with the above error. Sometimes it manages to complete but then suddenly quits after running for a while.

I'm sorry if this is not the right place to post this. I'm not sure if the issue is directly with storybook, Docker, my device, npm or devcontainers.

This only happens when I run it in the devcontainer. When I re-install node_modules on my host and run it, it works fine. I suspected memory issues but couldn't see anything of the sorts in the npm error nor anything suspicious when I monitored the containers memory usage.

(If it matters, I've posted most of my storybook config in another issue here: https://github.com/storybookjs/storybook/issues/14798)

Does this issue occur when you try this locally?: Only when run in container, does not happen when run directly on host Does this issue occur when you try this locally and all extensions are disabled?: -

Dockerfile:

# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/typescript-node/.devcontainer/base.Dockerfile

ARG VARIANT="14"
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}

# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
    && apt-get -y install --no-install-recommends build-essential python

# [Optional] Uncomment if you want to install more global node packages
RUN su node -c "npm install -g node-gyp"

devcontainer.json:


// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/typescript-node
{
  "name": "PROJ_X",
  "build": {
    "dockerfile": "Dockerfile",
    "args": {
      "VARIANT": "14"
    }
  },

  // Set *default* container specific settings.json values on container create.
  "settings": {
    "terminal.integrated.profiles.linux": {
      "bash": {
        "path": "/bin/bash"
      }
    },
    "terminal.integrated.defaultProfile.linux": "bash"
  },

  // Add the IDs of extensions you want installed when the container is created.
  "extensions": [
    "msjsdiag.debugger-for-chrome",
    "esbenp.prettier-vscode",
    "orta.vscode-jest",
    "jounqin.vscode-mdx",
    "editorconfig.editorconfig",
    "dbaeumer.vscode-eslint",
    "visualstudioexptteam.vscodeintellicode"
  ],

  // Use 'forwardPorts' to make a list of ports inside the container available locally.
  "forwardPorts": [3000, 6006],

  // Use 'postCreateCommand' to run commands after the container is created.
  "postCreateCommand": "npm install",

  // Docker CLI Args
  "runArgs": ["--memory=4g", "--cpus=2"],

  // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
  "remoteUser": "node"
}
chrmarti commented 3 years ago

Can you enable additional logging for the storybook command? This currently doesn't tell us why it exited with exit code 1.

tschanz-pcv commented 3 years ago

Ok, so I think I fixed it.

I think my initial hunch that it's a memory issue was correct. I did check memory usage and tried tweaking it with the runArgs but of course this doesn't help at all if Docker Desktop has his own internal limits that can't be exceeded! If only I would have known...

So I'm sorry for wasting your time; the solution was just to crank up the memory on the "Resources" section of Docker Desktop. Then the runArgs actually scaled the available memory up to 4g. Before it always ran the container with a 2GB limit which was not enough.