Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for file triggering before file is finished writing #24

Closed
adailey14 opened this issue Aug 31, 2016 · 9 comments
Closed

Wait for file triggering before file is finished writing #24

adailey14 opened this issue Aug 31, 2016 · 9 comments

Comments

@adailey14
Copy link

I reported this before at some point, but it's back and is happening more often now for my growing project. When I am compiling my project using 'npm run dev' I run into this error every few times I build:

[universal-webpack] Your server source file must export a function. Got '{}'

I find that if I add a 1 second timeout to 'wait for file.js' I get rid of the error:

//around line 47
if (condition_is_met)
{
  setTimeout(done, 1000);
  // instead of return done()
}

I believe what is happening is while the file is writing, the filesystem will report that it exists. But then when the file is loaded via 'require', the contents are not fully written, so it fails and returns an empty {}. By putting in the 1 second delay, the file is able to finish writing.

An alternative solution would be to make server.js retry requiring 'starter' (after a delay) when it doesn't return a function. Let me know if you need further info.

@catamphetamine
Copy link
Owner

Just to make sure: are you having that error message with the latest version?
It used to be JSON.stringify( in the older version, but then became util.inspect(.

Also, you can add an extra debugging line in node_modules/universal-webpack/build/server.js:

        // Start webpage rendering server
        // (this module will be compiled by Webpack server-side build from './source/server.js')

        const starter = require(server_bundle_path)

console.log('@@@@@@@@@@@@', require('fs').readFileSync(server_bundle_path, 'utf8'))

And see what are the actual contents of the file.

@adailey14
Copy link
Author

Ok I will try this. I do have the latest version I was typing the error from memory so not quite right.

@adailey14
Copy link
Author

adailey14 commented Aug 31, 2016

Ok here is what I got on my first try (looks like the file contents are a few blank lines?). I will try a few more times and see if I get a different result:

(waiting for Webpack build to finish)
("/Users/andrewdailey/Code/mortgagehipporeact/build/server/server.js" not found)
(waiting for Webpack build to finish)
("/Users/andrewdailey/Code/mortgagehipporeact/build/server/server.js" not found)
(waiting for Webpack build to finish)
("/Users/andrewdailey/Code/mortgagehipporeact/build/server/server.js" not found)
(waiting for Webpack build to finish)
@@@@@@@@@@@@ 


Error: [universal-webpack] Your server source file must export a function. Got {}
    at /Users/myname/Code/myproject/node_modules/universal-webpack/source/server.js:68:3

@catamphetamine
Copy link
Owner

Hmm, really, two blank lines.
You can change it even further to:

console.log('@' + require('fs').readFileSync(server_bundle_path, 'utf8') + '@')

To know for sure

@catamphetamine
Copy link
Owner

As for the solution, I could, for example, check for the file contents.
If it's blank, then try after a second (recursively).
I guess I'll go that route.

@adailey14
Copy link
Author

Tried with the second console.log options, and got no contents:

("/Users/andrewdailey/Code/mortgagehipporeact/build/server/server.js" not found)
(waiting for Webpack build to finish)
@@
Error: [universal-webpack] Your server source file must export a function. Got {}

@catamphetamine
Copy link
Owner

Oh, that's better. So it's not blank, it's simply empty. That makes sense. Releasing the fix.

@catamphetamine
Copy link
Owner

Try the latest version and see if it works for you (in time)

@adailey14
Copy link
Author

Ok great thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants