question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@babel/register write cache fail in node:alpine docker container

See original GitHub issue

Bug Report

  • I would like to work on a fix!

Current Behavior In node:alpine docker image. The folder node_modules create by root. And node server runs by ‘node’ user. So node_modules isn’t writeable.

cache.js not handle ENOENT error. It just throw out and crash node server.

/home/node/app/node_modules/@babel/register/lib/cache.js:80
        throw e;
        ^

Error: ENOENT: no such file or directory, mkdir '/home/node/app/node_modules/.cache/@babel/register'
    at Object.mkdirSync (fs.js:856:3)
    at module.exports.sync (/home/node/app/node_modules/make-dir/index.js:97:6)
    at save (/home/node/app/node_modules/@babel/register/lib/cache.js:61:23)
    at processTicksAndRejections (internal/process/task_queues.js:79:11) {
  errno: -2,
  syscall: 'mkdir',
  code: 'ENOENT',
  path: '/home/node/app/node_modules/.cache/@babel/register'
}

Input Code

  • REPL or Repo link if applicable:
var your => (code) => here;

Expected behavior/code A clear and concise description of what you expected to happen (or code).

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
  "your": { "config": "here" }
}

Environment


  • Babel version(s): v7.8.3
  • Node/npm version: Node v13.8.0/npm 6.13.6
  • OS: Alpine Linux
  • Monorepo: no
  • How you are using Babel: register

Possible Solution

Additional context/Screenshots Add any other context about the problem here. If applicable, add screenshots to help explain.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JLHwungcommented, Feb 12, 2020

As a workaround, you can disable the register cache via BABEL_DISABLE_CACHE env

ENV BABEL_DISABLE_CACHE 1

If node_modules is not writable due to permission errors, it should throw EACCESS instead of ENOENT. Babel will ignore the EACCESS error and produce warnings only.

Per http://man7.org/linux/man-pages/man3/errno.3.html

ENOENT: No such file or directory (POSIX.1-2001). Typically, this error results when a specified path‐name does not exist, or one of the components in the directory prefix of a pathname does not exist, or the specified pathname is a dangling symbolic link.

In your case, maybe /home/node/app/node_modules is a dangling symbolic link mounted by Docker. @cncolder Can you share the reproducing Dockerfile?

0reactions
JLHwungcommented, Feb 20, 2020

@cncolder Thanks for the reproduction Dockerfile. I can confirm this issue can be reproduced and thus I have filed one to the make-dir repo: https://github.com/sindresorhus/make-dir/issues/25

make-dir is used in babel-register to create cache directory. Note that this issue does not affect Babel 8, where make-dir has been replaced by native recursive fs.mkdir supported on node>=10.12.

It seems that fs.mkdir will throws ENOENT on the following cases and make-dir aligns to its behaviour.

mkdir -m 0100 foo
node -e "require('fs').mkdirSync('foo/bar')"
# Error: EACCES

node -e "require('fs').mkdirSync('foo/bar', { recursive: true })"
# Error: ENOENT

mkdir foo/bar
# Error: Permission Denied

It has been fixed recently on Node.js: (issue: https://github.com/nodejs/node/issues/31481)

Before we dropped node.js <= 13 support, we should workaround this node bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node and docker - how to handle babel or typescript build?
I'm not so familiar with typescript, but here's an example implementation using yarn and babel. Using this Dockerfile, we can build a development...
Read more >
Node.js Docker workflow - Guillaume Jacquart - Medium
Docker compose is a tool by Docker which allows you to define your whole application stack (app services, databases, cache layer, …) as...
Read more >
Optimizing builds with cache management
Understanding Docker's build cache helps you write better Dockerfiles that result in faster builds. Have a look at the following example, which shows...
Read more >
Docker build fails with nonsensical EPERM: operation not ...
I have a circleci build that's failing when it tries to build a Docker image. Specifically it fails when it tries to execute...
Read more >
Docker build not using cache - GitLab Forum
I am trying to speed up my Docker build by using the --cache-from option. This works on my local machine but not on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found