devcontainers / templates

Repository for Dev Container Templates that are managed by Dev Container spec maintainers. See https://github.com/devcontainers/template-starter to create your own!
https://containers.dev/templates
MIT License
859 stars 226 forks source link

typescript-node npm scripts error access #240

Closed DevinsonAlvarez closed 4 months ago

DevinsonAlvarez commented 4 months ago

Hi, I'm trying build a typescript-node container but when I using npm install or npm run dev throws the next errors:

$ npm install
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /workspaces/react-app/node_modules/@esbuild/aix-ppc64
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/workspaces/react-app/node_modules/@esbuild/aix-ppc64'
npm ERR!  [Error: EACCES: permission denied, mkdir '/workspaces/react-app/node_modules/@esbuild/aix-ppc64'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/workspaces/react-app/node_modules/@esbuild/aix-ppc64'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
$ npm run dev

> react-app@0.0.0 dev
> vite

failed to load config from /workspaces/react-app/vite.config.ts
error when starting dev server:
Error: EACCES: permission denied, open '/workspaces/react-app/vite.config.ts.timestamp-1708117025459-8405b36e7d40a.mjs'

This error solves when I run as root using sudo npm install/run dev but I thing it is not the best idea to always run these commands as root. This is my .devcontainer file:

{
  "name": "React App",
  "image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye",

  "forwardPorts": [5173],

  "runArgs": ["--name", "react-app-devcontainer"],

  "postCreateCommand": "npm install",

  "customizations": {
    "vscode": {
      "extensions": [
        "dsznajder.es7-react-js-snippets",
        "esbenp.prettier-vscode",
        "dbaeumer.vscode-eslint",
        "ms-vscode.vscode-typescript-next"
      ]
    }
  }
}
DevinsonAlvarez commented 4 months ago

The error happened because I build the contrainer from WSL and the permissions were not assigned to the node user, I solved it by changing the owner on folder using sudo chown -R $USER . && npm install. This problem only happened while using WSL.