Tailwind CSS 当 运行 项目在节点 Docker 容器中时出现 EACCESS 错误(Docker 组合)
Tailwind CSS EACCESS Error When Running Project In Node Docker Container (Docker Compose)
我有一个项目正在使用 svelte-kit 和 Tailwind CSS。我最近将其移至使用 docker 撰写。当我 运行 我的容器时,我 运行 它们在 WSL 中,因为它们通常 运行 在那里更好。当我启动 运行 开发服务器的容器时,它启动并且 运行 一切正常,但是当我在浏览器中打开 URL 时,出现以下错误。
Error: EACCES: permission denied, mkdir '/root/.tailwindcss/touch'
at Object.mkdirSync (node:fs:1325:3)
at Object.<anonymous> (/var/www/html/node_modules/tailwindcss/jit/lib/setupContext.js:44:8)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (/var/www/html/node_modules/tailwindcss/jit/index.js:7:22)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
我不确定是什么导致了这个错误,但我认为它与顺风有关。
这是我的 docker-compose 文件的 link:https://github.com/DriedSponge/GorillianCurrencyConversion/blob/master/docker-compose.yml
如果您想自己尝试一下,这里有一个 link 到 repo 和重现的步骤:
https://github.com/DriedSponge/GorillianCurrencyConversion
安装包:docker-compose run npm install
启动开发服务器:docker-compose --profile dev up -d --build
如果您对正在发生的事情有任何想法,或者您需要我提供任何其他信息,请告诉我。提前致谢!
看起来 Tailwind 是 trying to create a touch file which has something to do with watching for file changes during development, specifically when Tailwind is in JIT mode。
您可以通过以下任一方法解决此问题:
- 允许写入访问
/root/.tailwindcss
。
- 通过设置
TAILWIND_DISABLE_TOUCH
环境变量禁用触控。
- 通过将
TAILWIND_TOUCH_DIR
环境变量设置为允许写入的位置来更改 touch 文件目录。
要设置环境变量,在 package.json
文件中设置它们可能最方便。只需在scripts
下相关命令前添加环境变量即可,如:
"dev": "TAILWIND_TOUCH_DIR='/var/www/html/.tailwindcss/touch' svelte-kit dev"
注意不要将此目录指向包含重要文件的目录,因为 Tailwind 会删除该目录中的所有文件。
None 这些选项在除 comments in the source 之外的任何地方都有记录,所以我不完全确定这样做的后果是什么,尤其是在开发模式下。我相信这是用于文件更改时的通信,因此选项 1 或 3 可能是最安全的选择。
我有一个项目正在使用 svelte-kit 和 Tailwind CSS。我最近将其移至使用 docker 撰写。当我 运行 我的容器时,我 运行 它们在 WSL 中,因为它们通常 运行 在那里更好。当我启动 运行 开发服务器的容器时,它启动并且 运行 一切正常,但是当我在浏览器中打开 URL 时,出现以下错误。
Error: EACCES: permission denied, mkdir '/root/.tailwindcss/touch'
at Object.mkdirSync (node:fs:1325:3)
at Object.<anonymous> (/var/www/html/node_modules/tailwindcss/jit/lib/setupContext.js:44:8)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (/var/www/html/node_modules/tailwindcss/jit/index.js:7:22)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
我不确定是什么导致了这个错误,但我认为它与顺风有关。 这是我的 docker-compose 文件的 link:https://github.com/DriedSponge/GorillianCurrencyConversion/blob/master/docker-compose.yml
如果您想自己尝试一下,这里有一个 link 到 repo 和重现的步骤: https://github.com/DriedSponge/GorillianCurrencyConversion
安装包:docker-compose run npm install
启动开发服务器:docker-compose --profile dev up -d --build
如果您对正在发生的事情有任何想法,或者您需要我提供任何其他信息,请告诉我。提前致谢!
看起来 Tailwind 是 trying to create a touch file which has something to do with watching for file changes during development, specifically when Tailwind is in JIT mode。
您可以通过以下任一方法解决此问题:
- 允许写入访问
/root/.tailwindcss
。 - 通过设置
TAILWIND_DISABLE_TOUCH
环境变量禁用触控。 - 通过将
TAILWIND_TOUCH_DIR
环境变量设置为允许写入的位置来更改 touch 文件目录。
要设置环境变量,在 package.json
文件中设置它们可能最方便。只需在scripts
下相关命令前添加环境变量即可,如:
"dev": "TAILWIND_TOUCH_DIR='/var/www/html/.tailwindcss/touch' svelte-kit dev"
注意不要将此目录指向包含重要文件的目录,因为 Tailwind 会删除该目录中的所有文件。
None 这些选项在除 comments in the source 之外的任何地方都有记录,所以我不完全确定这样做的后果是什么,尤其是在开发模式下。我相信这是用于文件更改时的通信,因此选项 1 或 3 可能是最安全的选择。