sveltejs / sapper

The next small thing in web development, powered by Svelte
https://sapper.svelte.dev
MIT License
7k stars 434 forks source link

npm run dev: Error: ENOENT: no such file or directory, open '__sapper__/build/build.json' #627

Open btakita opened 5 years ago

btakita commented 5 years ago

To reproduce, run

npm run dev

Then, while dev is running, run npm run build

The npm run dev process will get the following error:

Error: ENOENT: no such file or directory, open '__sapper__/build/build.json'

vladejs commented 5 years ago

npm run build is an important ritual that should be run alone :)

thgh commented 5 years ago

+1 for allowing parallel build & dev

btakita commented 5 years ago

It seems like the issue is with

fs.writeFileSync(path.join(dest, 'build.json'), JSON.stringify(build_info));

https://github.com/sveltejs/sapper/blob/master/src/api/build.ts#L113

The watch process is running in parallel. If a temp file were written & then moved, via the shell, to the dest/build.json, then the operation should be atomic from an OS perspective.

The fs-write-stream-atomic write-file-atomic npm package should perform this. This project is under npm.

It looks like fs-write-stream-atomic is a dependency of Sapper.

brightchip commented 4 years ago

How to solve this ?

evdama commented 4 years ago

I tried with a fresh install and Sapper 0.28.1 and I'm getting this error as well 🤔 Screen Shot 2020-08-26 at 07 19 28

maxmilton commented 4 years ago

I didn't realise this issue was already open... I've created a new issue https://github.com/sveltejs/sapper/issues/1440 with more detailed information and a repro repo. The cause behind the error now is different to when this issue was opened so maybe it's time to close this one?

btakita commented 4 years ago

@MaxMilton These appear to be separate issues. I'm still getting this (https://github.com/sveltejs/sapper/issues/627) issue with the 0.28.4 release. This issue is not a race condition. It occurs every time npm run build is invoked when npm run dev is already running.

To reproduce:

In console 1

npm run dev

...wait for the dev server to start...

In console 2

npm run build
yangdachaun commented 3 years ago

root@dev-VirtualBox:/media/sf_work/ewechat# npm run dev Error: ENOENT: no such file or directory, uv_cwd at process.wrappedCwd (internal/bootstrap/switches/does_own_process_state.js:128:26) at process.cwd (/root/.nvm/versions/node/v12.18.3/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:10:19) at Conf.loadPrefix (/root/.nvm/versions/node/v12.18.3/lib/nodemodules/npm/lib/config/load-prefix.js:46:24) at load (/root/.nvm/versions/node/v12.18.3/lib/node_modules/npm/lib/config/core.js:109:8) at Conf. (/root/.nvm/versions/node/v12.18.3/lib/node_modules/npm/lib/config/core.js:96:5) at Conf.emit (events.js:315:20) at ConfigChain._resolve (/root/.nvm/versions/node/v12.18.3/lib/node_modules/npm/node_modules/config-chain/index.js:281:34) at ConfigChain.add (/root/.nvm/versions/node/v12.18.3/lib/node_modules/npm/node_modules/config-chain/index.js:259:10) at Conf.add (/root/.nvm/versions/node/v12.18.3/lib/node_modules/npm/lib/config/core.js:338:27) at Conf. (/root/.nvm/versions/node/v12.18.3/lib/node_modules/npm/lib/config/core.js:314:25) internal/bootstrap/switches/does_own_process_state.js:128 cachedCwd = rawMethods.cwd(); ^

Error: ENOENT: no such file or directory, uv_cwd at process.wrappedCwd (internal/bootstrap/switches/does_own_process_state.js:128:26) at process.cwd (/root/.nvm/versions/node/v12.18.3/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:10:19) at process.errorHandler (/root/.nvm/versions/node/v12.18.3/lib/node_modules/npm/lib/utils/error-handler.js:183:30) at process.emit (events.js:315:20) at process._fatalException (internal/process/execution.js:165:25) { errno: -2, code: 'ENOENT', syscall: 'uv_cwd' }