Closed15

Next.js on Docker で npm install すると permission denied が出る

ndjndj

https://zenn.dev/ddpmntcpbr/books/rna-hands-on/viewer/next-05
↑の mui の lab を追加する工程で下記エラーが発生
Docker desktop for Mac を想定しているが Windows WSL2 + Docker CE で環境構築しているので、その違いもあるかもしれない

npm install @mui/lab
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /app/node_modules/@mui/private-themingnpm ERR! dest /app/node_modules/@mui/.private-theming-Qi9rht5l
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/app/node_modules/@mui/private-theming' -> '/app/node_modules/@mui/.private-theming-Qi9rht5l'
npm ERR!  [Error: EACCES: permission denied, rename '/app/node_modules/@mui/private-theming' -> '/app/node_modules/@mui/.private-theming-Qi9rht5l'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/app/node_modules/@mui/private-theming',
npm ERR!   dest: '/app/node_modules/@mui/.private-theming-Qi9rht5l'
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 ERR! A complete log of this run can be found in:npm ERR!     /root/.npm/_logs/2023-12-13T01_26_03_293Z-debug-0.log
ndjndj

エラーログを見てみる

cd root 
ls -a 
cd .npm/_logs
cat 2023-12-13T01_26_03_293Z-debug-0.log
ndjndj
0 verbose cli /usr/local/bin/node /usr/local/bin/npm
1 info using npm@9.2.0
2 info using node@v19.4.0
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 1ms
6 timing config:load:builtin Completed in 2ms
7 timing config:load:cli Completed in 1ms
8 timing config:load:env Completed in 0ms
9 timing config:load:file:/app/.npmrc Completed in 0ms
10 timing config:load:project Completed in 8ms
11 timing config:load:file:/root/.npmrc Completed in 0ms
12 timing config:load:user Completed in 0ms
13 timing config:load:file:/usr/local/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:setEnvs Completed in 1ms
16 timing config:load Completed in 13ms
17 timing npm:load:configload Completed in 13ms
18 timing npm:load:mkdirpcache Completed in 0ms
19 timing npm:load:mkdirplogs Completed in 0ms
20 verbose title npm install @mui/lab
21 verbose argv "install" "@mui/lab"
22 timing npm:load:setTitle Completed in 1ms
23 timing config:load:flatten Completed in 2ms
24 timing npm:load:display Completed in 2ms
25 verbose logfile logs-max:10 dir:/root/.npm/_logs/2023-12-13T01_26_03_293Z-
26 verbose logfile /root/.npm/_logs/2023-12-13T01_26_03_293Z-debug-0.log
27 timing npm:load:logFile Completed in 3ms
28 timing npm:load:timers Completed in 0ms
29 timing npm:load:configScope Completed in 0ms
30 timing npm:load Completed in 20ms
31 silly logfile start cleaning logs, removing 1 files
32 timing config:load:flatten Completed in 1ms
33 timing arborist:ctor Completed in 1ms
34 silly logfile done cleaning log files
35 timing idealTree:init Completed in 144ms
36 timing idealTree:userRequests Completed in 2ms
37 silly idealTree buildDeps
38 silly fetch manifest @mui/lab@*
39 http fetch GET 200 https://registry.npmjs.org/@mui%2flab 17ms (cache hit)
40 silly fetch manifest @emotion/react@^11.11.1
41 http fetch GET 200 https://registry.npmjs.org/@emotion%2freact 7ms (cache hit)
42 silly fetch manifest react@18.2.0
43 timing arborist:ctor Completed in 0ms
44 http fetch GET 200 https://registry.npmjs.org/react 527ms (cache hit)
45 silly fetch manifest @emotion/styled@^11.11.0
46 http fetch GET 200 https://registry.npmjs.org/@emotion%2fstyled 5ms (cache hit)
47 silly fetch manifest @mui/material@^5.14.20
48 http fetch GET 200 https://registry.npmjs.org/@mui%2fmaterial 5ms (cache hit)
49 silly fetch manifest @types/react@18.2.42
50 http fetch GET 200 https://registry.npmjs.org/@types%2freact 4ms (cache hit)
51 silly fetch manifest react-dom@18.2.0
52 http fetch GET 200 https://registry.npmjs.org/react-dom 7ms (cache hit)
53 silly placeDep ROOT @mui/lab@5.0.0-alpha.156 OK for: my-app@0.1.0 want: *
54 silly fetch manifest @mui/base@5.0.0-beta.27
55 silly fetch manifest @mui/system@^5.15.0
56 silly fetch manifest @mui/types@^7.2.11
57 silly fetch manifest @mui/utils@^5.15.0
58 http fetch GET 200 https://registry.npmjs.org/@mui%2fbase 10ms (cache hit)
59 http fetch GET 200 https://registry.npmjs.org/@mui%2fsystem 12ms (cache hit)
60 http fetch GET 200 https://registry.npmjs.org/@mui%2futils 12ms (cache hit)
61 http fetch GET 200 https://registry.npmjs.org/@mui%2ftypes 14ms (cache hit)
62 timing idealTree:#root Completed in 611ms
63 silly fetch manifest @types/react@^17.0.0 || ^18.0.0
64 silly fetch manifest react@^17.0.0 || ^18.0.0
65 silly fetch manifest react-dom@^17.0.0 || ^18.0.0
66 silly fetch manifest @emotion/react@^11.5.0
67 silly fetch manifest @emotion/styled@^11.3.0
68 silly placeDep node_modules/@mui/lab @mui/base@5.0.0-beta.27 OK for: @mui/lab@5.0.0-alpha.156 want: 5.0.0-beta.27
69 silly placeDep ROOT @mui/system@5.15.0 REPLACE for: @mui/lab@5.0.0-alpha.156 want: ^5.15.0
70 silly placeDep ROOT @mui/types@7.2.11 REPLACE for: @mui/lab@5.0.0-alpha.156 want: ^7.2.11
71 silly placeDep ROOT @mui/utils@5.15.0 REPLACE for: @mui/lab@5.0.0-alpha.156 want: ^5.15.0
72 silly fetch manifest @mui/private-theming@^5.15.0
73 silly fetch manifest @mui/styled-engine@^5.15.0
74 http fetch GET 200 https://registry.npmjs.org/@mui%2fprivate-theming 8ms (cache hit)
75 http fetch GET 200 https://registry.npmjs.org/@mui%2fstyled-engine 8ms (cache hit)
76 timing idealTree:node_modules/@mui/lab Completed in 23ms
77 silly placeDep ROOT @mui/private-theming@5.15.0 OK for: @mui/system@5.15.0 want: ^5.15.0
78 silly placeDep ROOT @mui/styled-engine@5.15.0 OK for: @mui/system@5.15.0 want: ^5.15.0
79 timing idealTree:node_modules/@mui/system Completed in 4ms
80 timing idealTree:node_modules/@mui/private-theming Completed in 0ms
81 timing idealTree:node_modules/@mui/styled-engine Completed in 0ms
82 timing idealTree:node_modules/@mui/types Completed in 0ms
83 timing idealTree:node_modules/@mui/utils Completed in 0ms
84 timing idealTree:node_modules/@mui/lab/node_modules/@mui/base Completed in 0ms
85 timing idealTree:buildDeps Completed in 638ms
86 timing idealTree:fixDepFlags Completed in 2ms
87 timing idealTree Completed in 789ms
88 timing reify:loadTrees Completed in 789ms
89 timing reify:diffTrees Completed in 267ms
90 silly reify mark retired [ '/app/node_modules/@mui/private-theming' ]
91 silly reify mark retired [ '/app/node_modules/@mui/styled-engine' ]
92 silly reify mark retired [ '/app/node_modules/@mui/system' ]
93 silly reify mark retired [ '/app/node_modules/@mui/types' ]
94 silly reify mark retired [ '/app/node_modules/@mui/utils' ]
95 silly reify moves {
95 silly reify   '/app/node_modules/@mui/private-theming': '/app/node_modules/@mui/.private-theming-Qi9rht5l',
95 silly reify   '/app/node_modules/@mui/styled-engine': '/app/node_modules/@mui/.styled-engine-H0zj2zbk',
95 silly reify   '/app/node_modules/@mui/system': '/app/node_modules/@mui/.system-tdyIi51j',
95 silly reify   '/app/node_modules/@mui/types': '/app/node_modules/@mui/.types-riFE2zY8',
95 silly reify   '/app/node_modules/@mui/utils': '/app/node_modules/@mui/.utils-4FEzOK2A'
95 silly reify }
96 timing reify:rollback:retireShallow Completed in 19ms
97 timing command:install Completed in 1135ms
98 verbose stack Error: EACCES: permission denied, rename '/app/node_modules/@mui/private-theming' -> '/app/node_modules/@mui/.private-theming-Qi9rht5l'
99 verbose cwd /app
100 verbose Linux 5.15.133.1-microsoft-standard-WSL2
101 verbose node v19.4.0
102 verbose npm  v9.2.0
103 error code EACCES
104 error syscall rename
105 error path /app/node_modules/@mui/private-theming
106 error dest /app/node_modules/@mui/.private-theming-Qi9rht5l
107 error errno -13
108 error [Error: EACCES: permission denied, rename '/app/node_modules/@mui/private-theming' -> '/app/node_modules/@mui/.private-theming-Qi9rht5l'] {
108 error   errno: -13,
108 error   code: 'EACCES',
108 error   syscall: 'rename',
108 error   path: '/app/node_modules/@mui/private-theming',
108 error   dest: '/app/node_modules/@mui/.private-theming-Qi9rht5l'
108 error }
109 error
109 error The operation was rejected by your operating system.
109 error It is likely you do not have the permissions to access this file as the current user
109 error
109 error If you believe this might be a permissions issue, please double-check the
109 error permissions of the file and its containing directories, or try running
109 error the command again as root/Administrator.
110 verbose exit -13
111 timing npm Completed in 1168ms
112 verbose unfinished npm timer reify 1702430763323
113 verbose unfinished npm timer reify:retireShallow 1702430764383
114 verbose code -13
115 error A complete log of this run can be found in:
115 error     /root/.npm/_logs/2023-12-13T01_26_03_293Z-debug-0.log
ndjndj

なにか書き換えようとしている??
試しに axios (既に install 済み), moment(未 install)を npm install してみる

npm install axios 
> 成功
npm install moment
> 成功
ndjndj

ここが重要っぽい
ディレクトリを rename するときに権限エラーが発生している

108 error [Error: EACCES: permission denied, rename '/app/node_modules/@mui/private-theming' -> '/app/node_modules/@mui/.private-theming-Qi9rht5l'] {
108 error   errno: -13,
108 error   code: 'EACCES',
108 error   syscall: 'rename',
108 error   path: '/app/node_modules/@mui/private-theming',
108 error   dest: '/app/node_modules/@mui/.private-theming-Qi9rht5l'
108 error }
ndjndj

build 時間が 60 秒 → 800秒くらいになった・・・

ndjndj

chown やめたら build 時間がだいぶ短くなった(800秒→110秒)

ndjndj

node_modules を削除→npm install してみる

ndjndj

いけたかも
力技だがとりあえずこれで進める

このスクラップは2023/12/19にクローズされました