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.

`vite build` should not write a files outside of explicitly set directories (`build.outDir`, etc.)

See original GitHub issue

Description

I run vite inside a docker container for security reasons.

My docker run looks like:

docker container run -d --rm --name "myApp" \
	-v "~/myApp:/var/www/myApp:ro" \
	-v "~/myApp/tmp:/var/www/myApp/tmp:rw" \
	-v "~/myApp/logs:/var/www/myApp/logs:rw" \
	-v "~/myApp/package-lock.json:/var/www/myApp/package-lock.json:rw" \
	"myApp:latest"

As you can see, the application code files are read-only and they can’t be changed from inside the docker container (for example, some mistake like rm -rf * can’t remove all my code files).

But since version 3.0.1, vite build creates the vite.config.js.mjs file in the root directory, and since version 3.0.3 it creates a file with a random name like vite.config.js.timestamp-1659277944620.mjs.

Because my application root is the read-only, then docker container exec -i "myApp" bash -l -c 'npm run build' fails with error:

failed to load config from /var/www/myApp/vite.config.js
error during build:
Error: EROFS: read-only file system, open '/var/www/myApp/vite.config.js.timestamp-1659277944620.mjs'

Suggested solution

Write file only to explicitly set directories.

Alternative

No response

Additional context

No response

Validations

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bluwycommented, Jul 31, 2022

vite.config.js.timestamp-1659277944620.mjs is a file bundled by Vite to read the config file. It happens for TS by default in Vite 3.0.0, and expanded to do so for JS too in Vite 3.0.1.

It doesn’t generate to build.outDir because the import paths would then be different. I’m not sure how this can be fixed in Vite, but the Docker setup may need to relax a bit for now, until something like https://github.com/vitejs/vite/issues/5370#issuecomment-1193357749 is implemented.

0reactions
lyleafcommented, Sep 22, 2022

I solved it by just using a python yaml instead of a nodejs yaml, as mine is a static website.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build Options - Vite
It will emit a warning if outDir is outside of root to avoid accidentally removing important files. You can explicitly set this option...
Read more >
Configuring Vite
When running vite from the command line, Vite will automatically try to resolve a config file named vite.config.js inside project root.
Read more >
Configuring Vite
When running vite from the command line, Vite will automatically try to resolve a config file named vite.config.js inside project root. The most...
Read more >
Building for Production - Vite
This option can also be specified as a command line flag, e.g. vite build --base=/my/public/path/ . JS-imported asset URLs, CSS url() references, and...
Read more >
Write to disk option for Vite - javascript - Stack Overflow
publicDir)) { const destPath = path.join(config.build.outDir ... It will also re-write the file if any of the files within the public folder ......
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